建立系結控制碼
分散式應用程式的用戶端程式必須建立系結控制碼,告知 RPC 執行時間應連絡哪部伺服器,以及如何連絡伺服器。
下列程式碼片段示範建立系結控制碼的常見方法:
RPC_STATUS status;
unsigned short *StringBinding;
RPC_BINDING_HANDLE BindingHandle;
status = RpcStringBindingCompose(NULL, // Object UUID
L"ncacn_ip_tcp", // Protocol sequence to use
L"MyServer.MyCompany.com", // Server DNS or Netbios Name
NULL,
NULL,
&StringBinding);
// Error checking ommitted. If no error, we proceed below
status = RpcBindingFromStringBinding(StringBinding, &BindingHandle);
// free string regardless of errors from RpcBindingFromStringBinding
RpcStringFree(&StringBinding);
// Error checking ommitted. If no error, we have a valid binding handle