描述:
我现在写一个vc ATL com dll,在dll的接口中定义一个带BSTR类型参数的方法
::F1(BSTR tempStr1)
{
}
编译通过无问题,但如果再定义一个传引用的参数的方法
::F2(BSTR &tempStr)
{
}
编译时系统报告“expecting a declarator or * near "&"”,什么原因,可我要把tempStr的结果返回调用程序,如何实现呢?谢谢!
解决方案1:
首先用不着引用,直接用指针即可。
关于赋值,方法有很多的。
最简单的方法:CString a="asfsd";
CComBSTR b=a.AllocSysString();
tempStr=b.copy();即可。
如果你是Unicode编译的话,可以直接CComBSTR b=L"asfsd";
做成activx控件后,生成的类中,此函数的声明为:
CString get_GetVersion()
{
CString result;
InvokeHelper(0xa, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}
不要在参数里返回。
[propget, id(10), helpstring("method GetVersion")] HRESULT GetVersion([out,retval] BSTR *bstrVersion);