Difference between revisions of "RPC HELP DLL GuideLines C Initialize LoadLibrary GetProcAddress"

From VistApedia
Jump to: navigation, search
 
 
Line 2: Line 2:
  
 
[[RPC_HELP_Other_DLL_Interface_List|DLL Interface Home]]
 
[[RPC_HELP_Other_DLL_Interface_List|DLL Interface Home]]
 +
<h2>C: Initialize -- LoadLibrary and GetProcAddress</h2>
 +
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 cases where functions are not found. */
 +
      return 1;
 +
    }
 +
 +
Now you can use functions exported in the DLL.

Latest revision as of 16:28, 8 July 2015

RPC Broker Help Home

DLL Interface Home

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 cases where functions are not found. */
     return 1;
   }

Now you can use functions exported in the DLL.