How To Use RPC Callback Functions

 
This article was previously published under Q96781

SUMMARY

<script type="text/javascript">loadTOCNode(1, 'summary');</script>
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

<script type="text/javascript">loadTOCNode(1, 'moreinformation');</script>
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
				

APPLIES TO
Microsoft Win32 Software Development Kit (SDK) 3.1
Microsoft Win32 Software Development Kit (SDK) 3.5
Microsoft Win32 Software Development Kit (SDK) 3.51
Microsoft Win32 Software Development Kit (SDK) 4.0
Keywords: 
kbhowto kbapi kbrpc kbnetwork KB96781
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值