C: Initialize - LoadLibrary and GetProcAddress

The first step to using the RPC Broker 32-bit DLL in a C program is to load the DLL and get the process addresses for the exported functions.

To initialize access to the Broker DLL functions:

  1. Use the Windows API LoadLibrary function to load the DLL.
    HINSTANCE hLib = LoadLibrary("bapi32.dll");
    if((unsigned)hLib<=HINSTANCE_ERROR)
    {
       /* add your error handler for case where library fails to load */
       return 1;
    }
  2. If you successfully load the DLL, map function pointers to the addresses of the functions in the DLL that you need for your application.
    RPCBCreate = (void *(__stdcall*)()) GetProcAddress(hLib, "RpcbCreate");
    RPCBFree = (void (__stdcall*)(void *)) GetProcAddress(hLib, "RpcbFree");
    RPCBCall = (char *(__stdcall*)(void *, char *)) GetProcAddress(hLib, "RpcbCall");
    RPCBCreateContext = (bool (__stdcall*)(void *, char *)) GetProcAddress(hLib, "RpcbCreateContext");
    RPCBMultSet = (void (__stdcall*)(void *, int, char *, char *)) GetProcAddress(hLib, "RpcbMultSet");
    RPCBParamGet = (void (__stdcall*)(void *, int, int, char *)) GetProcAddress(hLib, "RpcbParamGet");
    RPCBParamSet = (void (__stdcall*)(void *, int, int, char *)) GetProcAddress(hLib, "RpcbParamSet");
    RPCBPropGet = (void (__stdcall*)(void *, char *, char *)) GetProcAddress(hLib, "RpcbPropGet");
    RPCBPropSet =(void (__stdcall*)(void *, char *, char *)) GetProcAddress(hLib, "RpcbPropSet");
    //
    // GetProcAddress returns null on failure
    //
    if( RPCBCreate == NULL || RPCBFree == NULL || RPCBCall == NULL || RPCBCreateContext == NULL
       || RPCBMultSet == NULL || RPCBParamGet == NULL || RPCBParamSet == NULL || RPCBPropGet == NULL
       || RPCBPropSet == NULL)
    {
    /* add your error handler for case where functions are not found */
       return 1;
    }

Now you can use functions exported in the DLL.