Introduction to RPC on Windows: Part I - Doing the RPC stuff
(Page 3 of 6 )
Now in order to make the above program use RPC we need to define an interface first that this program may use. So let’s type into a plain text file the interface definition using IDL and save it as DoRPC.idl. I’ll explain the meaning of each line with a comment.
// File DoRPC.idl
[
// A unique identifier that distinguishes this
// interface from other interfaces.
uuid(F0C37BD0-0D1B-4513-8C51-EC0D699740C0),
// This is version 1.0 of this interface.
version(1.0),
// This interface will use an implicit binding
// handle named hDoRPCBinding.
implicit_handle(handle_t hDoRPCBinding)
]
interface DoRPC // The interface is named DoRPC
{
// A function that takes a zero-terminated string.
void Show( [in, string] const char* szMsg);
}
As a companion to this IDL file we also need to write an Application Configuration File (.acf) with the following text and save it as DoRPC.acf. in the same directory as the IDL file.
// File DoRPC.acf
[
// This interface will use an implicit binding handle named hDoRPCBinding.
implicit_handle(handle_t hDoRPCBinding)
]
interface DoRPC // The interface is named DoRPC
{
}
Now you may ask the MIDL compiler to generate the source code for you that you may use in your client/server application. To generate the files invoke the tool MIDL.exe as follows:
MIDL /app_config /no_cpp DoRPC.idl
If this doesn’t work, you may have to run the vcvars32.bat file to setup the environment variables. This will generate three files for you: DoRPC.h, DoRPC_c.c, and DoRPC_s.c. The files with .c extensions are the source code files generated for the client and server side implementation of the interface; they can be distinguished by the _c and the _s appended to filename. These filenames are, however, configurable through command line switches. This situation can be explained as in the diagram below.

Figure 1: Using the MIDL compiler
Next: Writing Server Side code >>
More .NET Articles
More By Digvijay Chauhan
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|