解譯系結資訊
Microsoft RPC 可讓您的用戶端和伺服器程式存取系結句柄中的資訊並加以解譯。 這並不表示您可以或應該嘗試直接存取系結句柄的內容。 Microsoft RPC 提供函式,可設定和擷取系結句柄中的資訊。
若要取得系結句柄中的資訊,請將句柄傳遞至 RpcBindingToStringBinding。 它會以字串的形式傳回系結資訊。 對於每個對 RpcBindingToStringBinding的呼叫,您必須有對應的對函式 RpcStringFree的呼叫。
您可以呼叫函式 RpcStringBindingParse 來剖析您從 RpcBindingToStringBinding取得的字串。 此函式會配置字串來包含其剖析的資訊。 如果您不想剖析特定系結資訊片段,請將 NULL 當做該參數的值傳遞。 請務必針對它配置的每個字串呼叫 RpcStringFree。
下列代碼段說明應用程式如何呼叫這些函式。
RPC_STATUS status;
UCHAR *lpzStringBinding;
UCHAR *lpzProtocolSequence;
UCHAR *lpzNetworkAddress;
UCHAR *lpzEndpoint;
UCHAR *NetworkOptions;
// The variable hBindingHandle is a valid binding handle.
status = RpcBindingToStringBinding(hBindingHandle,&lpzStringBinding);
// Code to check the status goes here.
status = RpcStringBindingParse(
lpzStringBinding,
NULL,
&lpzProtocolSequence;
&lpzNetworkAddress;
&lpzEndpoint;
&NetworkOptions);
// Code to check the status goes here.
// Code to analyze and alter the binding information in the strings
// goes here.
status = RpcStringFree(&lpzStringBinding);
// Code to check the status goes here.
status = RpcStringFree(&lpzProtocolSequence);
// Code to check the status goes here.
status = RpcStringFree(&lpzNetworkAddress);
// Code to check the status goes here.
status = RpcStringFree(&NetworkOptions);
// Code to check the status goes here.
上述範例程式代碼會 呼叫 rpcBindingToStringBinding 和 RpcStringBindingParse 函式,以取得和剖析有效系結句柄中的資訊。 請注意,NULL 的值會當做第二個參數傳遞至 RpcStringBindingParse。 這會導致該函式略過剖析物件 UUID。 因為它不會剖析 UUID,RpcStringBindingParse 不會為其配置字串。 這項技術可讓應用程式只配置記憶體,以取得您想要剖析和分析的資訊。