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.
#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 closes or deletes an object in this way, the application can no longer use the object using the C++ API.
Being able to use the C API is useful if a C++ application needs to use function that is available only in the C API. The function described in C functions that return a string or byte array by reference is an example of such function.