Just my luck, when using the vc++ compiler the problem doesn't occur. The code compiles (after some minor tweaks) and my ofstream stuff works and I can step over the breakpoints.
The same code, when compiled with gcc 3.4.5 doesn't work (code in DllMain doesn't execute).
Any suggestions as to how I go from here? Anyone heard of something like this before? - Seems like it's gcc /MingW specific.
Do you have error checking and reporting in you client? Do you know that LoadLibrary() isn't failing? etc...
Thanks for the time you're putting in to helping me out. I'm not doing much error checking in the client, however I'm fairly sure LoadLibrary() isn't failing. Code is as follows:
If LoadLibrary was failing, I'd have expected to have had "Fail" echo out, but it doesn't. If I debug the app and set a breakpoint on the "Fail" cout, it's never reached.
using namespace std;
typedef char* (*version)();
int main(int argc, char *argv)
HINSTANCE hInst = LoadLibrary( "myFile.dll" );
if( hInst )
_version = (version)GetProcAddress( hInst, "version" );
if( _version )
cout << "Version: " << _version() << ::endl;
FreeLibrary( hInst ); ///< Free up DLL.
cout << "Fail" << ::endl;
::cin.get(); ///< Wait for user to hit return key before exiting.
Try adding the text in red. C++ name mangling may be preventing the CRT startup code from linking with your DllMain.
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
That did it, I would never have though to mark DllMain with extern "C".
If you're ever in Dorset (UK) I owe you a beer or two!
>>If you're ever in Dorset (UK) I owe you a beer or two!
If CodePlug ever called in all the beers he was owed he would drink himself to death!