Calling App Functions from DLL
I've created a DLL, exported the proper functions, and everything seems to be working fine; the main application can look up the exported function with GetProcAddress(), call them, and nothing unexpected happens. Now I'm looking into having the DLL call some of the application's functions, and I'm running into trouble. The code I've attached illustrates the problem.
When the main application (MainApp) starts, it immediately loads the MainAppDLL with LoadLibrary(). This calls the DLL's DllMain(), which senses that the application is loading the module into its space and attempts to call an application-side function. Since the main application is already technically loaded into the process space, the DLL uses GetModuleHandle(NULL) to get a handle to the main application's instance for use in GetProcAddress() rather than LoadLibrary(). However, GetProcAddress() always returns NULL and GetLastError() reports that the procedure hasn't been found.
I can see why this is; opening the MainApp executable in a hex editor, I wasn't able to find the standard (function name)@(number) text anywhere in the file as I would see in a DLL even though the function is exported in MainApp's code. Is __declspec(dllexport) meaningless when used in an executable? Is there a way to get a pointer to a function in an application so that a DLL may call it?