Is it possible to export an EXE function like we do with DLLs? My EXE loads a DLL. I would like that my DLL could use a function in my EXE. Is this possible? Thanks in advance.
when you link your exe, us link /SUBSYTEM:WINDOWS /EXPORT:nameoffunctiontoexport yourexe.obj Below sample code would export one function. and call it from itself.
I threw this code together at work, so excuse the sloppyness hope this helps prs
to compile and test ;ml /c /coff /Cp exportexe.asm ;link /SUBSYSTEM:WINDOWS /EXPORT:MyExeExPort exportexe.obj ; .586 .model flat, stdcall MyExeExport proto :DWORD, :DWORD include d:\masm32\include\windows.inc include d:\masm32\include\kernel32.inc include d:\masm32\include\user32.inc includelib d:\masm32\lib\user32.lib includelib d:\masm32\lib\kernel32.lib .data szExe db "exportexe.exe",0 exExport db "MyExport",0 .code start: invoke LoadLibrary, addr szExe .if eax push eax invoke GetProcAddress, eax, addr exExport .if eax push offset szExe push offset exExport call eax .endif pop eax invoke FreeLibrary, eax .endif invoke ExitProcess, eax MyExport proc public pq, pd invoke MessageBox, NULL, pq, pd, NULL ret MyExport endp end start
ps. If you want to test this just compile and link it. Then Rename it to something else, then compile and link again. or just run it by itself. take care prs
You could always just create a DEF file, in exactly the same way as for a DLL, but make sure you include it when you build the executable. Once you've exported the functions you can generate a LIB file and use it during linking in the normal way, rather than calling the GetProcAddress function. Nick