+ Reply to Thread
Results 1 to 2 of 2

Thread: How to dynamically load a DLL in C++?

  1. #1

    How to dynamically load a DLL in C++?

    Hi all,

    How to dynamically load a DLL in C++?

    Thanks.

  2. #2
    Hi all,

    DLL can be loaded using "LoadLibrary" API.
    Function pointer from the DLL can be received by "GetProcAddress" API.
    Loaded DLL need to be freed using "FreeLibrary" API.

    Following is the example:

    Code:
    void UseLoadLibrary()
    {
    	HMODULE hDLL = LoadLibrary("MyDLL.dll") ;
    
    	if (NULL != hDLL)
    	{
    		typedef void (*PFNDISPLAYMESSAGE) (char *) ;
    		PFNDISPLAYMESSAGE pfnDisplayMessage = NULL ;
    		pfnDisplayMessage = (PFNDISPLAYMESSAGE) GetProcAddress(hDLL, "DisplayMessage") ;
    		pfnDisplayMessage("Ronit") ;
    		FreeLibrary(hDLL) ;
    		hDLL = NULL ;
    	}
    }
    Thanks.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts