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.
Posted on 2001-04-26 13:27:00 by Master-Dude
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.

to compile and test
;ml /c /coff /Cp exportexe.asm
;link /SUBSYSTEM:WINDOWS /EXPORT:MyExeExPort exportexe.obj

.model flat, stdcall

MyExeExport proto :DWORD, :DWORD

include d:\masm32\include\
include d:\masm32\include\
include d:\masm32\include\

includelib d:\masm32\lib\user32.lib
includelib d:\masm32\lib\kernel32.lib


	szExe		db	"exportexe.exe",0
	exExport	db	"MyExport",0



	invoke LoadLibrary, addr szExe
	.if eax
	push eax
		invoke GetProcAddress, eax, addr exExport
		.if eax
			push offset szExe
			push offset exExport
			call eax
	pop eax
	invoke FreeLibrary, eax
	invoke ExitProcess, eax

MyExport proc public pq, pd

	invoke MessageBox, NULL, pq, pd, NULL

MyExport endp

end start
I threw this code together at work, so excuse the sloppyness hope this helps prs
Posted on 2001-04-26 15:50:00 by prs
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
Posted on 2001-04-26 15:59:00 by 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
Posted on 2001-04-27 06:03:00 by Nick