PreviousNext

Writing a C++ Client for C Servers

Suppose you are writing a C++ client that needs to use an interface definition that has not taken advantage of the IDL C++ features. A logical example is an older interface definition written prior to the introduction of the C++ features of OSF DCE Version 1.2. An older interface is not designed to specify a class of objects and the associated member functions. This means that servers for older interfaces do not maintain objects in the way described in this topic (if they maintain objects at all).

This topic uses the following simplistic interface for demonstration:

[
uuid(166ab38b-95f9-11ce-9387-08002b2bf322)
] interface old_interface
{
double op1();

void op2([in] long input);

void op3();
}

If you simply compile this interface definition for the C++ language and build the C++ client application, the application cannot invoke any of the old interface's member functions because no object can exist on a server. However, static member functions do not require an object in order to invoke them, so the solution is to make the operations of an older interface static member functions.

In order for your C++ client to use an older interface, perform the following steps:

1. Create an ACF for the interface and apply the cxx_static attribute to every operation of the interface. For example:

interface old_interface
{
[cxx_static] op1();
[cxx_static] op2();
[cxx_static] op3();
}

2. Use the IDL compiler with the -lang cxx option to compile the interface and generate the header files and C++ stubs. Link the code into your C++ client application as usual.

3. Call the static functions where needed in the C++ client application by using the scope operator (::). For example:

#include "old_interface.h"

main()
{
idl_long_float result;
idl_long_int input = 1;

result = old_interface::op1();
old_interface::op2(input);
old_interface::op3();
return 0;
}