组件对象模型自动化

时间:2018-04-12 17:38:02

标签: automation com

我想用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, &params, NULL, NULL,
                          NULL);  
  //pdisp IDispatch
_ASSERT(hr==S_OK);

但是我发现错误是因为Name变量定义 我的对象中的方法列表是:

addSimulationCase
getSimulationCase
importCase
openCase
registeredBoundaryEquipmentsList
registeredCorrelaionsList
registeredEquipmentsList
removeSimulationCase

请帮我定义指针名称。

1 个答案:

答案 0 :(得分:1)

名称import json # New data to add to the file unique_following = ['7', '8', '9', '7'] # Read in existing file with open('data.json') as fp: list_of_data = json.load(fp) dirty = False for f in unique_following: if not any(data['id'] == f for data in list_of_data['insta']): list_of_data['insta'].append({'id': f, 'dm': False}) dirty = True if dirty: # Write the file with new data with open('data.json', 'w') as fp: json.dump(list_of_data, fp, indent=1) 有点令人困惑。看起来好像你可以一次查询具有多个函数名的对象,就像你想要做的那样。不是这种情况。您只能查询单个函数名称。来自the documentation

  

当使用多个名称调用GetIDsOfNames时,使用名字   (rgszNames [0])对应于成员名称和后续名称   对应于成员参数的名称。

您需要为要呼叫的每个功能单独调用GetIDsOfNames