Share via


解譯系結資訊

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.

上述範例程式碼會呼叫 RpcBindingToStringBindingRpcStringBindingParse 函式,以取得和剖析有效系結控制碼中的資訊。 請注意, Null 值是以第二個參數的形式傳遞至 RpcStringBindingParse。 這會導致該函式略過剖析物件 UUID。 因為它不會剖析 UUID, RpcStringBindingParse 不會為其配置字串。 這項技術可讓應用程式只配置您有興趣剖析和分析之資訊的記憶體。