[id(1), helpstring("方法StartTalk")] int SendData(BSTR buffer);如何将BSTR-------->char类型
如何将char-------->BSTR类型int SendData(BSTR buffer)
{
    send(char *buffer);
}int ReadData(BSTR *buffer)
{
    read(char *buffer);
}

解决方案 »

  1.   

    BSTR转换成char*
    使用ConvertBSTRToString。例如:
    #include 
    #pragma comment(lib, "comsupp.lib")
    int _tmain(int argc, _TCHAR* argv[]){
    BSTR bstrText = ::SysAllocString(L"Test");
    char* lpszText2 = _com_util::ConvertBSTRToString(bstrText);
    SysFreeString(bstrText); // 用完释放
    delete[] lpszText2;
    return 0;
    } char*转换成BSTR
    使用SysAllocString等API函数。例如:
    BSTR bstrText = ::SysAllocString(L"Test");
    BSTR bstrText = ::SysAllocStringLen(L"Test",4);
    BSTR bstrText = ::SysAllocStringByteLen("Test",4);