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或者如果处理返回的值
{
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或者如果处理返回的值
ID.Format("%s",sIdentifyResults.szMatchedUserId);
//sIdentifyResults定义为上面的结构 *UserID = ID.SysAllocString();
-〉
*UserID = SysAllocString((BSTR)CComBSTR(ID));
->
USES_CONVERSION;
*UserID = SysAllocString(A2W(ID));还可以这样
CComBSTR bs(ID);
*UserID=bs.Deatach();