Wenn wir eine unbekannte Funktion in C++-Code haben, tun wir normalerweise folgendes:

/* declare the function */
int MyFunction(char *, int);
int main(void)
{
   return MyFunction("hello", 5);
}
 
/* our function */
int MyFunction(char *, int)
{
   /* do something */
   return 0;
}

Doch wir haben die Funktion in einer DLL. Die DLL ist beispielsweise im Rootverzeichnis des C:\-Laufwerks und heißt „MyDLL.dll“. Sie enthält die Funktion „MyFunction“. Nun erstellen wir eine Funktion, die die DLL-Funktion rufen kann:

int CallMyDLL(void)
{ 
   /* get handle to dll */
   HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\MyDLL.dll");
 
   /* get pointer to the function in the dll*/
   FARPROC lpfnGetProcessID = GetProcAddress(HMODULE
   (hGetProcIDDLL), "MyFunction");
 
   /*
    Define the Function in the DLL for reuse. This is just prototyping
    the dll's function. A mock of it. Use "stdcall" for maximum
    compatibility.
   */
   typedef int (__stdcall * pICFUNC)(char *, int);
 
   pICFUNC MyFunction;
   MyFunction = pICFUNC(lpfnGetProcessID);
 
   /* The actual call to the function contained in the dll */ 
   int intMyReturnVal = MyFunction("hello", 5);
 
   /* Release the Dll */
   FreeLibrary(hGetProcIDDLL);
 
   /* The return val from the dll */
   return intMyReturnVal;
}

Tools zum Sichten von DLLs: dumpbin, depends