Parallels Virtualization SDK
ContentsIndex
Example
PrlApi_Init Function

The following example illustrates how to perform the necessary API library initialization. 

The first step is to load the dynamic link library using the SdkWrap_Load function from the supplied wrapper library (SdkWrap is a helper library that contains just two functions for loading and unloading the API dynamic link library; the library is not documented in this guide). 

The second step is to initialize the Parallels API using the PrlApi_Init function. 

Once the above steps are completed, you are ready to make other API calls, such as PrlSrv_Login and others. 

On program exit, you must cal the PrlApi_Deinit function to deinitialize the API, and the SdkWrap_Unload function to unload the dynamic link libraries.

int main(int argc, char* argv[])
{
   // Pick the correct dynamic library depending on the platform.
   #ifdef _WIN_
      #define SDK_LIB_NAME "prl_sdk.dll"
   #elif defined(_LIN_)
      #define SDK_LIB_NAME "libprl_sdk.so"
   #elif defined(_MAC_)
      #define SDK_LIB_NAME "libprl_sdk.dylib"
   #endif

   // Load the dynamic library.
   // If the library cannot be found, try searching for it.
   if (PRL_FAILED(SdkWrap_Load(SDK_LIB_NAME)) &&
      PRL_FAILED(SdkWrap_Load("./" SDK_LIB_NAME)))
   {
      fprintf(stderr, "Failed to load " SDK_LIB_NAME "\n");
      return -1;
   }

   // Initialize the API.
   PRL_RESULT ret;
   ret = PrlApi_Init(PARALLELS_API_VER);
   if (PRL_FAILED(ret))
   {
      printf("PrlApi_Init returned with error (%s)\n",
      PRL_RESULT_TO_STRING(ret));
      return -1;
   }

   // your program code goes here...

   // Deinitialize the API.
   ret = PrlApi_Deinit();
   if (PRL_FAILED(ret))
   {
      printf("PrlApi_Deinit returned with error (%s)\n",
      PRL_RESULT_TO_STRING(ret));
      return -1;
   }

   // Unload dynamic link libraries.
   SdkWrap_Unload();
   return 0;
}
© 2021 Parallels International GmbH. All rights reserved.