Collapse All
Parallels Virtualization SDK
ContentsIndex
PreviousUpNext
PrlApi_Init Function
System Functions  Example  See Also

Initializes Parallels API library.

Syntax
PRL_RESULT PrlApi_Init(
    PRL_UINT32 version
);
File

PrlApiCore.h

Returns

PRL_RESULT. Possible values: 

PRL_ERR_DOUBLE_INIT - library has been already initialized. 

PRL_ERR_OUT_OF_MEMORY - not enough memory to initialize the library. 

PRL_ERR_API_INCOMPATIBLE - SDK version is incompatible with version in param. 

PRL_ERR_SUCCESS - operation completed successfully. 

Remarks

This function must be called after the dynamic libraries are loaded and before making any of the API calls. Internally, this call creates the internal event-loop and initializes the library state. Before exiting the program, the PrlApi_Deinit function must be called to perform internal library de-initialization.

Version

Library version number. This should be PARALLELS_API_VER. 

 

See Also
Example

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;
}
Links
© 2021 Parallels International GmbH. All rights reserved.