typedef struct
{
uint32 uiStructureSize ; // must be set to sizeof(tsAT_IDENTIFY_RESULTS_A) by application
uint16 uwMatchedNumber ;
char szMatchedUserId[24] ;
} tsAT_IDENTIFY_RESULTS_A ;
COM参数如何返回字符串值,函数代码
STDMETHODIMP CATSCCtl::Indentify(BSTR *UserID)
{
char* ID;
ID=sIdentifyResults.szMatchedUserId;
//sIdentifyResults定义为上面的结构 *UserID = SysAllocString((BSTR)ID);
}在VB中引用该COM,调用函数Indentify
dim strUserID AS String
Indentify  strUserID
Msgbox strUserID
总是显示乱码,单步运行调试我已经看到ID的值是正确的,如果我将其返回直接这样赋值 *UserID = SysAllocString(L"1234");在VB中就能正常显示1234,
请问我该怎么定义ID或者如果处理返回的值

解决方案 »

  1.   

    CString ID;
    ID.Format("%s",sIdentifyResults.szMatchedUserId);
    //sIdentifyResults定义为上面的结构 *UserID = ID.SysAllocString();
      

  2.   

    修改下面这句看看:*UserID = SysAllocString((BSTR)ID);
    -〉
    *UserID = SysAllocString((BSTR)CComBSTR(ID));
      

  3.   

    *UserID = L "1234"就可以了吧
      

  4.   

    “*UserID = L "1234"就可以了吧”俺的回答是不可以地.楼上几个的做法外,还可以*UserID = SysAllocString((BSTR)ID);
    ->
    USES_CONVERSION;
    *UserID = SysAllocString(A2W(ID));还可以这样
    CComBSTR bs(ID);
    *UserID=bs.Deatach();
      

  5.   

    非常感谢各位,使用 lcp(dupi) 的方法成功