Thread: FreeLibrary Quesion

  1. #1
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    FreeLibrary Quesion

    If I use the FreeLibrary function [FreeLibrary("dll_name.dll");] to free up the dll I'm using, the program executes the notice 3x (2x saying it successfully freed it up, and the last saying it didn't...so code below for details) the game crashes.

    I'm using Microsoft Visual C++ 6.0 w/ the Win32 API on a WinXP Home Edition system.

    If you want the source for the way I'm doing it, here it is:
    Code:
    #ifndef __GLOBALS_H
    #define __GLOBALS_H
    
    #include "log.h" // Logging works fine
    
    HINSTANCE tok = LoadLibrary("tokenizer.dll");	// Loads the tokenizer.dll
    
    // File-handling globals
    char szCode[1024];	// Arrary to hold the source code
    
    // Error handling
    char *szError;
    
    // Check to see if the library is free, if so, or if not, notify the user...even if something is wrong
    bool CheckFree()
    {
        if(tok) 
        {
    		bool Lib2Free = FreeLibrary(tok);
    
    		if(Lib2Free == false)
    		{
    			szError = "Unable to free tokenizer.dll!";
    			MessageBox(NULL, szError, NULL, NULL);
    			szDataToLog(szError);
    		}
    		else if(Lib2Free == true)
    		{
    			szError = "Successfully freed tokenizer.dll data!";
    			MessageBox(NULL, szError, NULL, NULL);
    			szDataToLog(szError);
    		}
    		else
    		{
    			szError = "Undefined exception, unable to determin tokenizer state!";
    			MessageBox(NULL, szError, NULL, NULL);
    			szDataToLog(szError);
    		}
    		return true;
        }
    
        else 
    	{
    		szError = "Unable to unload tokenizer.dll!";
    		MessageBox(NULL, szError, NULL, NULL);
    		szDataToLog(szError);
    	}
        return false;
    }
    
    #endif
    [I took out the stuff that isn't of any importance to my question.]

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Are you sending in the right handle?
    I think you could use GetModuleHandle() to do this.?

    Try to get extended errorinformation from GetLastError()
    Code:
    /************************************\
     * GetErr()                         *
     *	Fetches error information       *
     * Input:                           *
     *	src*	->sourcemodule for error  *
     * Output:                          *
     *	void                            *
     * Author: Knut Øverli              *
    \************************************/
    void GetErr(char *src){
    	char errBuf[400];
    	sprintf(errBuf, "Return from GetLastError(%lu), src:\"%s\":\n", GetLastError(), src);
    	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errBuf+strlen(errBuf), 399-strlen(errBuf), NULL);
    	b(0, errBuf, "System error", MB_ICONSTOP);
    }

  3. #3
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by knutso
    Are you sending in the right handle?
    I think you could use GetModuleHandle() to do this.?
    I re-programmed my project, and I don't have that error anymore. I'm not sure what was wrong, but I'm not gonna worry about it anymore. Thanks though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quesion about #define
    By Brimak86 in forum Windows Programming
    Replies: 1
    Last Post: 01-29-2008, 10:09 PM
  2. Quesion: Gather HDD Info
    By 4c00h in forum Windows Programming
    Replies: 5
    Last Post: 10-12-2006, 12:10 AM
  3. Replies: 4
    Last Post: 04-23-2006, 02:03 PM
  4. a java quesion: JFrame arrays
    By Commander in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 07-12-2003, 06:51 PM
  5. Quesion problem
    By datainjector in forum C Programming
    Replies: 5
    Last Post: 07-02-2002, 06:49 AM