Search code examples
automationcom

component object model Automation


I want to call the object of a software with COM interface. The method in my object is shown in the image and my code is given below:

::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);

But an error occurred I think its because of Name variable definition list of method in my object is :

addSimulationCase
getSimulationCase
importCase
openCase
registeredBoundaryEquipmentsList
registeredCorrelaionsList
registeredEquipmentsList
removeSimulationCase

please help me how define pointer Name.


Solution

  • The name GetIDsOfNames is a little confusing. It looks as if you can query the object with multiple function names at once, as you are trying to do. This is not the case. You can only query for a single function name. From 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.

    You need a separate GetIDsOfNames call for each function you want to call.