Understanding WCHAR**

Understanding WCHAR**

本文关键字:WCHAR Understanding      更新时间:2023-10-16

我需要传递WCHAR**类型变量来函数。我希望这个函数会给这个变量一些文本。但WCHAR**到底是什么?根据我的理解WCHAR*是指向数组WCHAR指针。 那么WCHAR*数组WCHAR**呢?

如何初始化此变量?

WCHAR** c;
void func (WCHAR** s)
{
}

编译器很生气,认为c没有初始化。如何处理?

这是从 wsdl 生成的用于 Web 服务的真实函数。我需要传递cConfig变量。

HRESULT WINAPI WSHttpBinding_ISupportService_ConfigToClient(
    __in WS_SERVICE_PROXY* _serviceProxy,
    __in int clientId, 
    __out int* ConfigToClientResult, 
    __inout_opt __deref __nullterminated WCHAR** cConfig, 
    __in WS_HEAP* _heap,
    __in_ecount_opt(_callPropertyCount) const WS_CALL_PROPERTY* _callProperties,
    __in const ULONG _callPropertyCount,
    __in_opt const WS_ASYNC_CONTEXT* _asyncContext,
    __in_opt WS_ERROR* _error)
{
    void* _argList[3]; 
    _argList[0] = &clientId;
    _argList[1] = &ConfigToClientResult;
    _argList[2] = &cConfig;
    return WsCall(_serviceProxy,
        (WS_OPERATION_DESCRIPTION*)&tempuri_org_wsdlLocalDefinitions.contracts.WSHttpBinding_ISupportService.WSHttpBinding_ISupportService_ConfigToClient.WSHttpBinding_ISupportService_ConfigToClient,
        (const void **)&_argList,
        _heap,
        _callProperties,
        _callPropertyCount,
        _asyncContext,
        _error);
}
const _tempuri_org_wsdl tempuri_org_wsdl =
{
    {// messages
        {    // message description for ISupportService_LogIt_InputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_LogIt_InputMessageactionName, // http://tempuri.org/ISupportService/LogIt
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.LogIt, 
        },    // message description for ISupportService_LogIt_InputMessage
        {    // message description for ISupportService_LogIt_OutputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_LogIt_OutputMessageactionName, // http://tempuri.org/ISupportService/LogItResponse
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.LogItResponse, 
        },    // message description for ISupportService_LogIt_OutputMessage
        {    // message description for ISupportService_getClientId_InputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_getClientId_InputMessageactionName, // http://tempuri.org/ISupportService/getClientId
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.getClientId, 
        },    // message description for ISupportService_getClientId_InputMessage
        {    // message description for ISupportService_getClientId_OutputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_getClientId_OutputMessageactionName, // http://tempuri.org/ISupportService/getClientIdResponse
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.getClientIdResponse, 
        },    // message description for ISupportService_getClientId_OutputMessage
        {    // message description for ISupportService_GetClientCommands_InputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_GetClientCommands_InputMessageactionName, // http://tempuri.org/ISupportService/GetClientCommands
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.GetClientCommands, 
        },    // message description for ISupportService_GetClientCommands_InputMessage
        {    // message description for ISupportService_GetClientCommands_OutputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_GetClientCommands_OutputMessageactionName, // http://tempuri.org/ISupportService/GetClientCommandsResponse
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.GetClientCommandsResponse, 
        },    // message description for ISupportService_GetClientCommands_OutputMessage
        {    // message description for ISupportService_ConfigToSrv_InputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_ConfigToSrv_InputMessageactionName, // http://tempuri.org/ISupportService/ConfigToSrv
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.ConfigToSrv, 
        },    // message description for ISupportService_ConfigToSrv_InputMessage
        {    // message description for ISupportService_ConfigToSrv_OutputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_ConfigToSrv_OutputMessageactionName, // http://tempuri.org/ISupportService/ConfigToSrvResponse
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.ConfigToSrvResponse, 
        },    // message description for ISupportService_ConfigToSrv_OutputMessage
        {    // message description for ISupportService_ConfigToClient_InputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_ConfigToClient_InputMessageactionName, // http://tempuri.org/ISupportService/ConfigToClient
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.ConfigToClient, 
        },    // message description for ISupportService_ConfigToClient_InputMessage
        {    // message description for ISupportService_ConfigToClient_OutputMessage
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.ISupportService_ConfigToClient_OutputMessageactionName, // http://tempuri.org/ISupportService/ConfigToClientResponse
            (WS_ELEMENT_DESCRIPTION*)&tempuri_org_xsd.globalElements.ConfigToClientResponse, 
        },    // message description for ISupportService_ConfigToClient_OutputMessage
    }, // messages
    {// contracts
        {   // WSHttpBinding_ISupportService
            5,
            (WS_OPERATION_DESCRIPTION**)tempuri_org_wsdlLocalDefinitions.contracts.WSHttpBinding_ISupportService.operations,
        },    // end of WSHttpBinding_ISupportService
    }, // contracts
    { // policies
        {  // template description for WSHttpBinding_ISupportService
            {  // channel properties
                (WS_CHANNEL_PROPERTY*)&tempuri_org_wsdlLocalDefinitions.policies.WSHttpBinding_ISupportService.channelPropertiesArray,
                3,
            },
        },  // end of template description
    },  // policies
    { // endpointReferences
        { // WSHttpBinding_ISupportService
            { // endpointAddressDescription
                WS_ADDRESSING_VERSION_1_0,
            },
            (WS_XML_STRING*)&tempuri_org_wsdlLocalDefinitions.dictionary.xmlStrings.WSHttpBinding_ISupportServiceendpointReferenceString, // <wsa10:EndpointReference xmlns:wsa10="http://www.w3.org/2005/08/addressing">...
        },  // endof WSHttpBinding_ISupportService
    },  // endof endpointReferences 
}; // end of _tempuri_org_wsdl
@crashmstr注释

中提供了答案,以下是您在实践中的做法,假设函数想要返回指向您的指针。

WCHAR* ptr = NULL;
func(&ptr);
if(ptr) {
    DoSomething(ptr);
    ...
    MaybeYouHaveToFreeThePointer(ptr);
}