Environments: VC ++ 6.0
1. Use the uuidgen.exe/I/rpc. IDL command to generate an rpc. IDL file (the file name must be of the. IDL type ).
The format of the generated file is as follows:
[
UUID (abb12775-f053-4c62-95c2-4d9bc7fdbfef ),
Version (1.0)
]
Interface interfacename
{
}
2. Write the function you want to call on the server in the brackets of interface interfacename.
For example: (the following code comes from: http://www.codeproject.com/KB/IP/rpcintro2.aspx)
// File contextexample. IDL
[
// A unique identifier that distinguishes this interface from other interfaces.
UUID (00000003-eaf3-4a7a-a0f2-bce4c30da77e ),
// This is version 1.0 of this interface.
Version (1.0)
]
Interface contextexample // The interface is named contextexample
{
// To fully use context handles we need to do a typedef.
Typedef [context_handle] void * context_handle;
// Open a context on the server.
Context_handle open (
// Explicit server binding handle.
[In] handle_t hbinding,
// String to be output on the server.
[IN, string] const char * szstring );
// Output the context string on the server.
Void output (
// Context handle. The binding handle is implicitly
// Used through the explicit context handle.
[In] context_handle hcontext );
// Closes a context on the server.
Void close (
// Context handle. The binding handle is implicitly
// Used through the explicit context handle.
[In, out] context_handle * phcontext );
}
3. Execute midl. EXE contextexample. IDL on the generated. IDL file (the file name depends on your own file name)
In this case, three contextexample. h contextexample_s.c contextexample_c.c files are generated.
4. generate two projects, one being the server and the other being the client.
Import contextexample. IDL contextexample. h contextexample_s.c to the server project;
Import contextexample. IDL contextexample. h contextexample_c.c to the client project.
5. Compile the implementation code of the called function on the server side, and write the call code on the client side to test the RPC-based c/s program.
However, this method is more suitable for some practical applications than directly using socket or csocket. It is still to be tested!