Using RPC Callback Functions

Last reviewed: November 2, 1995
Article ID: Q96781
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5, 3.51, and 4.0

SUMMARY

The standard remote procedure call (RPC) model has a server containing one or more exported function calls, and a client, which calls the server's exported functions. However, Microsoft's implementation of RPC defines callbacks as a special interface definition language (IDL) attribute allowing a server to call a client function.

Callbacks can be used only in the context of a server call. Thus, a server may call a client's callback function only when the server is performing a client's remote procedure call (before it returns from processing). For example:

                CLIENT                SERVER
                ------                ------

       Client makes RPC call. --->
                                <--- Server calls callback procedure.
Client returns from callback. --->
                                <--- Server calls callback procedure.
Client returns from callback. --->
                                <--- Server returns from original RPC call.

MORE INFORMATION

Callbacks are declared in the RPC .IDL file and defined in the source of the client. The following demonstrates how callbacks are declared and defined:

[ SAMPLE.IDL ] [

   uuid(9FEE4F51-0396-101A-AE4F-08002B2D0065),
   version(1.0),
   pointer_default( unique )
]

{

 void RPCProc( [in, string] unsigned char *pszStr );
 [callback] void CallbackProc([in,string] unsigned char *pszStr);
}

[ SAMPLEC.C (Client)]

/*
   Callback RPC call (initiated from server, executed on client).
*/
void CallbackProc( unsigned char *pszString )
{
  printf("Call from server, printed on client: %s", pszStr );
}

[ SAMPLES.C (Server)]

/*
   "Standard" RPC call (initiated from client, executed on server).
   Makes a call to client callback procedure, CallbackProc().
*/
void RPCProc( unsigned char *pszStr )
{
  printf("About to call Callback() client function.."
  CallbackProc( pszStr );
  printf("Called callback function.");
}

In the makefile for the sample, the "-ms_ext" switch must be used for the MIDL compile. For example:

   midl -ms_ext -cpp_cmd $(cc) -cpp_opt "-E" sample.idl


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbnetwork
KBSubcategory: NtwkRpc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.