读书人

VB里怎的调用VC的COM接口中[out]类的参

发布时间: 2012-12-30 10:43:14 作者: rapoo

VB里怎样调用VC的COM接口中[out]类的参数
如题
[解决办法]
out的意思是输出参数
有out属性的参数必须是指针

[id(1), helpstring("method TestMethod")] HRESULT TestMethod([out] BSTR* outstr, [out] double* outdbl, [out] IDispatch** outobj);

STDMETHODIMP CTestClass::TestMethod(BSTR *outstr, double *outdbl, IDispatch **outobj)
{
*outstr = _bstr_t("你好!").copy();
*outdbl = 3.1415926;
_COM_SMARTPTR_TYPEDEF(IDispatch, __uuidof(IDispatch));
IDispatchPtr p;
p.CreateInstance("scripting.dictionary");
*outobj = p;
p.AddRef();
return S_OK;
}


Private Sub Form_Load()
Dim outstr As String
Dim outdbl As Double
Dim outobj As Object

Dim tc As New TestClass
Call tc.TestMethod(outstr, outdbl, outobj)

MsgBox outstr
MsgBox outdbl
MsgBox TypeName(outobj)
End Sub

读书人网 >VB

热点推荐