0

I am loading the C++ DLL dynamically into the exe written in C++.

My requirement is

1) Loading the DLL dynamicaaly using LoadLibrary()

2) The calling the GetProcAddress more than few time to assign same function pointer as the functions get called in DLL has got the same signature.

3) So Do I have to release any resources in my code for lpfn function pointer before the second function (Function_2) gets called?

//Function pointer
typedef int (__stdcall *EntryPoint)(int nContext, BYTE *pySeed, int nSeedSize, BYTE *pyKey, int *pnKeySize);

int main()
{
HMODULE hDllHandle = LoadLibrary("SA.dll");  // load dll

    if (hDllHandle)
    {
     EntryPoint lpfn= 0;

         if (lpfn = (EntryPoint)GetProcAddress(hDllHandle, "Function_1"))
         {
                 //call the function using lpfn
         }
         else
         {

         }
         //should I release any resources on lpfn before I call/assign 
         // second function  
         if (lpfn = (EntryPoint)GetProcAddress(hDllHandle, "Function_2"))
         {
                 //call the function using lpfn
         }
         else
         {

         }        
     }  
}
Raj
  • 151
  • 1
  • 14

1 Answers1

1

Huh? The function returns an integer/address. If you reuse your variable lpfn in a loop or so then your variable value gets overwritten.

You might rather consider freeing your strings (function names) when you don't need them anymore.

This address is not like a chunk from the heap that needs special freeing.

Joker007
  • 11
  • 4