I have an executable file (which I created using Visual C ++ 10), and I need to use its capabilities from another program that I wrote (in the same environment). Due to the complex deployment requirements that I will not deal with, creating a DLL from the required functionality and loading it into both programs is not something I can do.
So, I thought I could __declspec(dllexport) some functions in an EXE, and then LoadLibrary() provide me with GetProcAddress() them.
Obviously, this cannot be done, although when I started looking at it, it seemed practically feasible.
In particular, when you are __declspec(dllexport) in an EXE project, Visual C ++ also creates a lib file for dynamic linking, so you donโt even need to use LoadLibrary() - just a link to the resulting lib and function call.
Unfortunately, the main problem is that when you declare the resulting file as EXE, Visual C ++ adds the "CRTmain" access point to the resulting file instead of the "CRTDLLmain" that the DLL receives. When Windows (automatically) LoadLibrary() EXE from your main program, it does not call the entry point "CRTDLLmain" (since it does not exist), the C runtime for the module is not initialized, and as a result all the interesting work (for example, memory allocation) fails with interesting (*) runtime exceptions.
So my question is: is there a way to get Visual C ++ to embed the CRTmain entry point and the CRTDLLmain entry point in the resulting file?
(*) "Interesting," as in an ancient Chinese curse.
c windows visual-c ++ visual-studio-2010
Guss
source share