Introduction to RPC on Windows, Part II - Implicit binding handles
(Page 4 of 5 )
With implicit binding handles, the client program gets a chance to configure the binding handle before the binding actually takes place. Once the client establishes a binding, the RPC run-time library takes over and handles the rest of the communication on its own. Thus implicit binding handles allow your application to specify a server as the target to your remote procedure calls. Here you need to set the binding information as the client application starts executing so that it may create the binding. After the binding is created once, the client application does not need to pass any binding handles as a parameter to remote procedure calls it makes because it has already "Implicitly" expressed that. The other chores of the communication session are managed by the RPC Runtime automatically.
The client application needs to store this binding information as an implicit handle in a global variable. When the MIDL compiler generates the client stub and header file from the interface specification in your MIDL file (as we saw in the last article), it also generates code for a global binding handle variable that stores the binding handle value once the client creates it, and then it need not refer to it again until it explicitly destroys the binding.
You can create an implicit binding handle by specifying the [implicit_handle] attribute in the ACF (Application Configuration File) for the RPC interface as follows:
/* ACF file */
[
implicit_handle(handle_t hImplicit)
]
interface IMyRemoteProcedures
{
HRESULT MyRemoteCall();
}
The handle_t data type, which we used in the example above, is a MIDL data type used for defining binding handles.
After creating the implicit handle as shown above, you may use this handle whenever you make calls to the RPC run-time library functions. Please note that the implicit handle must never be passed as a parameter to the remote procedure calls you make. The following code snippet shows the correct usage of implicit binding handles.
RPC_STATUS status;
status = RpcBindingFromStringBinding( pszStringBinding, &hImplicit);
status = MyRemoteCall();
status = RpcBindingFree(hImplicit);
// other code
In the above example, the RPC run-time library functions RpcBindingFromStringBinding and RpcBindingFree required the implicit binding handle, which we save after binding is established, to be passed in their parameter lists. However, the remote procedure MyRemoteCall did not, since it is not an RPC run-time library function.
Next: Explicit binding handles >>
More .NET Articles
More By Digvijay Chauhan