Hi all there,
I never did but isn't it possible to compile an executeable that holds exported functions? so that loadlibrary + GetProcAddress works on that exe? What do I need to tell link & ml exe ?
Dominik
I never did but isn't it possible to compile an executeable that holds exported functions? so that loadlibrary + GetProcAddress works on that exe? What do I need to tell link & ml exe ?
Dominik
Don't you just add /EXPORT:ProcName to the LINK command line ? You may have to declare the proc as PUBLIC and STDCALL as well, not too familiar with how to do it in MASM.
Do I need a .def file?
If you have multiple exports it can be easier with a DEF file, but adding it directly to the link command line is enough. A DEF file only provides a list of command line options to LINK.EXE, it is never absolutely necessary, even for DLLs. Just be sure not to include the LIBRARY directive in the DEF file :
<start of file>
EXPORTS
SomeProc1
SomeProc2
<end of file>
on the link command line include:
/DEF:file.def
<start of file>
EXPORTS
SomeProc1
SomeProc2
<end of file>
on the link command line include:
/DEF:file.def
I can't get it to work. The linker always tells me that he does not know the exported function: "Unresolved external symbol"...
Does anyone know how to do it? this is my attempt:
ml.exe /c /Cp /coff %1.asm
link.exe /Subsystem:windows /entry:DllEntry /def:%1.def %1.obj
my ASM File:
The DEF file:
Does anyone know how to do it? this is my attempt:
ml.exe /c /Cp /coff %1.asm
link.exe /Subsystem:windows /entry:DllEntry /def:%1.def %1.obj
my ASM File:
.386
.model flat, STDCALL
option casemap :none
include \masm32\include\windows.inc
include macros.inc
includeboth kernel32
includeboth user32
ExportFunction PROTO
.data
.code
Main:
Unload:
invoke ExitProcess, 0h
end Main
DllEntry proc hInstDll:DWORD, dwNotification:DWORD, lpReserved:DWORD
return TRUE
DllEntry endp
ExportFunction proc
ret
ExportFunction endp
end DllEntry
The DEF file:
LIBRARY "test"
EXPORTS
ExportFunction
You appear to have 2 entry points to the program, you can only have a single END directive as that is what defines the entry point. Also you are creating an EXE so you should not be specifying a library in the DEF file. I had absolutely no problems with the following...
The DEF file was as follows:
The link command line :
I was able to extract an address using GetProcAddress in GoAsm (I didn't bother with MASM for the extraction) Calling the function as follows returned 100:
.386
.model flat, stdcall
option casemap :none
include Test.inc
Public stdcall TestProc
.data
hInstance dd 0
.code
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke ExitProcess,0
;########################################################################
TestProc proc
mov eax,100
ret
TestProc endp
end start
The DEF file was as follows:
EXPORTS
TestProc
The link command line :
LINK.EXE /DEF:Test.def /SUBSYSTEM:WINDOWS /VERSION:4.0 /LIBPATH:"C:\Masm32\Lib" "Test.obj"
I was able to extract an address using GetProcAddress in GoAsm (I didn't bother with MASM for the extraction) Calling the function as follows returned 100:
invoke LoadLibraryA,"Test.exe"
mov [hLib],eax
invoke GetProcAddress,[hLib],"TestProc"
call eax ;<< Returns 100
invoke FreeLibrary,[hLib]
Your're the man, donkey. That was all I ever asked for.
What happens when the executeable library gets loaded? Any idea of how to include a DllEntry-like procedure?
Dominik
What happens when the executeable library gets loaded? Any idea of how to include a DllEntry-like procedure?
Dominik
Hi Dom,
If you want a DLL like entry procedure you can always just write a DLL and use RunDLL32 to run it as a normal application.
If you want a DLL like entry procedure you can always just write a DLL and use RunDLL32 to run it as a normal application.
Somehow all references to data structures (in TestFunction) lead to an error when loading the library/executeable and calling the GetProcAddress-value of "TestFunction"...? Perhaps I need to give a specific base address as linker parameter /BASE: ... ???
Dominik
Dominik