组件对象模型自动化
component object model Automation
我想调用一个有COM接口的软件的对象。我的对象中的方法如图所示,我的代码如下:
::CLSIDFromProgID(OLESTR("SGNSAutomation.SGNSApplication"), &clsid);
IID iid;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,
IID_IDispatch, (LPVOID*)&pWMPDispatch);
IDispatch * pdisp = (IDispatch *)NULL;
DISPID dispid;
DISPPARAMS params = {NULL};
OLECHAR * Name = OLESTR("addSimulationCase","getSimulationCase","importCase","openCase","registeredBoundaryEquipmentsList","registeredCorrelaionsList","registeredEquipmentsList","removeSimulationCase");
HRESULT hresult =pWMPDispatch->GetIDsOfNames(IID_NULL, &Name,8,LOCALE_SYSTEM_DEFAULT,&dispid);
hresult =pWMPDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, NULL, NULL,
NULL);
//pdisp IDispatch
_ASSERT(hr==S_OK);
但是发生了一个错误,我认为是因为 Name 变量定义
我的对象中的方法列表是:
addSimulationCase
getSimulationCase
importCase
openCase
registeredBoundaryEquipmentsList
registeredCorrelaionsList
registeredEquipmentsList
removeSimulationCase
请帮我定义指针名称。
这个名字GetIDsOfNames
有点让人迷惑。看起来您可以像您尝试的那样一次查询具有多个函数名称的对象。不是这种情况。您只能查询单个函数名称。来自 the documentation:
When GetIDsOfNames is called with more than one name, the first name
(rgszNames[0]) corresponds to the member name, and subsequent names
correspond to the names of the member's parameters.
您需要为每个要调用的函数单独 GetIDsOfNames
调用。
我想调用一个有COM接口的软件的对象。我的对象中的方法如图所示,我的代码如下:
::CLSIDFromProgID(OLESTR("SGNSAutomation.SGNSApplication"), &clsid);
IID iid;
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL,
IID_IDispatch, (LPVOID*)&pWMPDispatch);
IDispatch * pdisp = (IDispatch *)NULL;
DISPID dispid;
DISPPARAMS params = {NULL};
OLECHAR * Name = OLESTR("addSimulationCase","getSimulationCase","importCase","openCase","registeredBoundaryEquipmentsList","registeredCorrelaionsList","registeredEquipmentsList","removeSimulationCase");
HRESULT hresult =pWMPDispatch->GetIDsOfNames(IID_NULL, &Name,8,LOCALE_SYSTEM_DEFAULT,&dispid);
hresult =pWMPDispatch->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, ¶ms, NULL, NULL,
NULL);
//pdisp IDispatch
_ASSERT(hr==S_OK);
但是发生了一个错误,我认为是因为 Name 变量定义 我的对象中的方法列表是:
addSimulationCase
getSimulationCase
importCase
openCase
registeredBoundaryEquipmentsList
registeredCorrelaionsList
registeredEquipmentsList
removeSimulationCase
请帮我定义指针名称。
这个名字GetIDsOfNames
有点让人迷惑。看起来您可以像您尝试的那样一次查询具有多个函数名称的对象。不是这种情况。您只能查询单个函数名称。来自 the documentation:
When GetIDsOfNames is called with more than one name, the first name (rgszNames[0]) corresponds to the member name, and subsequent names correspond to the names of the member's parameters.
您需要为每个要调用的函数单独 GetIDsOfNames
调用。