WebSphere Message Service Client for C/C++, Version 2.0.2 Operating Systems: AIX, Linux, Solaris, Windows

Use of C APIs in a C++ application

Most C++ classes supplied with XMS provide a getHandle() method. A C++ application can call the getHandle() method of an object to retrieve the handle that a C application would use to access the object. The C++ application can then use the handle to access the object by calling functions in the C API.

The following code fragment illustrates how this is done:
#include <xms.hpp>

using namespace std;

int main(int argc, char *argv[])
{
  xms::ConnectionFactory cf;
  xms::Connection        conn;
  xmsHConn               hConn;

  cf.setIntProperty(XMSC_CONNECTION_TYPE, XMSC_CT_RTT);
  cf.setIntProperty(XMSC_RTT_CONNECTION_PROTOCOL, XMSC_RTT_CP_TCP);
  cf.setStringProperty(XMSC_RTT_HOST_NAME, "localhost");
  cf.setIntProperty(XMSC_RTT_PORT, 1506);

  conn = cf.createConnection();

  // Retrieve the handle for the connection.

  hConn = conn.getHandle();

  // Using the retrieved handle, call a C API function.

  xmsConnStart(hConn, NULL);

  // Other code here

  return(0);
}

Using the handle for an object, a C++ application can close or delete the object by calling the appropriate C API function. However, if a C++ application does that it can no longer use the object using the C++ API.

Being able to use the C API is useful because some functions are available only in the C API. An example of such a function is described in C functions that return a string or byte array by reference.


Concept topic

Terms of Use | Rate this page

Last updated: 24 May 2011

(C) Copyright IBM Corporation 2005, 2011. All Rights Reserved.