我在Windows XP上运行来自c ++的com脚本
通常脚本执行没有问题,但有时执行失败,并且使用了hresult DISP_E_MEMBERNOTFOUND。 (调用是失败的功能)
有人知道为什么会这样吗?
代码在
CLSID clsid;
MULTI_QI mqi;
HRESULT hr ;
mqi.hr = 0;
mqi.pIID = &IID_IDispatch;
mqi.pItf = NULL;
hr = CLSIDFromProgID(T2W(progId.c_str()), &clsid);
CHECK_HRESULT(hr);
hr = CoCreateInstanceEx(clsid, NULL, CLSCTX_INPROC_SERVER, NULL, 1, &mqi);
CHECK_HRESULT(hr);
tMethodArguments argTemp(arguments.size()) ;
USES_CONVERSION ;
HRESULT hr;
DISPID index ;
OLECHAR FAR* szMember = T2W(method.c_str());
unsigned int err ;
hr = m_pScriptComObj->GetIDsOfNames( IID_NULL, &szMember, 1, LOCALE_SYSTEM_DEFAULT, &index ) ;
CHECK_HRESULT(hr);
DISPPARAMS params ;
params.rgvarg = pArgs ;
params.rgdispidNamedArgs = NULL ;
params.cArgs = arguments.size() ;
params.cNamedArgs = 0 ;
EXCEPINFO excep_info;
hr = m_pScriptComObj->Invoke(index,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
¶ms,
&res,
&excep_info,
&err);
我省略了方法和参数初始化
INVOKE调用的vbscript看起来像这样
<?xml version="1.0"?>
<component id="script_wsc_script">
<?component?>
<registration
description="script_wsc_script"
progid="wscScript.WSC"
version="1.00"
classid="{A1C14070-EBAB-41A0-BC9C-B4330A73437D}"
remotable="true"
>
</registration>
<public>
<method name="PrintMessage">
<PARAMETER name="first"/>
<PARAMETER name="second"/>
</method>
</public>
<script language="VBScript">
<![CDATA[
Function PrintMessage ( first, second)
''do something
End Function