Thread: HMODULE from current DLL

  1. #16
    Registered User
    Join Date
    Dec 2003
    Posts
    68
    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.

  2. #17
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Do you have error checking and reporting in you client? Do you know that LoadLibrary() isn't failing? etc...

    gg

  3. #18
    Registered User
    Join Date
    Dec 2003
    Posts
    68
    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:

    Code:
    using namespace std;
    
    typedef char* (*version)();
    
    int main(int argc, char *argv[])
    {
    	version _version;
    
    	HINSTANCE hInst = LoadLibrary( "myFile.dll" );
    
    	if( hInst )
    	{
    		_version = (version)GetProcAddress( hInst, "version" );
    		if( _version )
    		{
    			cout << "Version: " << _version() << ::endl;
    		}
    
    		FreeLibrary( hInst );	///< Free up DLL.
    	}
    	else
    	{
    		cout << "Fail" << ::endl;
    	}
    
    	::cin.get();	///< Wait for user to hit return key before exiting.
    
        return 0;
    }
    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.

  4. #19
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    extern "C"
    BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    Try adding the text in red. C++ name mangling may be preventing the CRT startup code from linking with your DllMain.

    gg

  5. #20
    Registered User
    Join Date
    Dec 2003
    Posts
    68
    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!

  6. #21
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>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!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  3. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM