Iteration of COMAddIns Collection using C

J

javajetprogrammer

Hi all:

I need to run a COM addin in process from a C program. I'm a newbie to C
programming.

I am able to get a pointer to the IDispatch interface via CoCreateInstance.

I can get a pointer to the COMAddIns Collection Object and its count propery
value.

I'm stuck on how to interate the collection and get each COMAddin via the
index or ProgID property.

Any help would be greatly appreciated. Code snippet below, if it helps.


IDispatch *pCOMAddIns; //IDispatch pointer to COMAddins collection
DISPID dispID; // Temporary variable to hold DISPIDs.
HRESULT hr; // General error/result holder.

VARIANT varRetVal;
VARIANTARG varg;
DISPPARAMS dp = { NULL, NULL, 0, 0 };

LPOLESTR szCOMAddIns = L"COMAddIns";
LPOLESTR szCount = L"Count";
LPOLESTR szItem = L"Item";


int COMAddInsCount;



// Retrieve COMAddIns dispid.
hr = pDisp->lpVtbl->GetIDsOfNames(pDisp, &IID_NULL, &szCOMAddIns, 1,
LOCALE_USER_DEFAULT, &dispID);

// Retrieve the IDispatch pointer to the COMAddIns object.
dp.cArgs = 0;
dp.rgvarg = NULL;
hr = pDisp->lpVtbl->Invoke(pDisp,dispID, &IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET | DISPATCH_METHOD, &dp, &varRetVal, NULL, NULL);

pCOMAddIns = varRetVal.pdispVal;

// Retrieve the dispid for the Count property of the COMAddIns object.
hr = pCOMAddIns->lpVtbl->GetIDsOfNames(pCOMAddIns, &IID_NULL, &szCount, 1,
LOCALE_SYSTEM_DEFAULT, &dispID);

// Retrieve the value of the Count property.
dp.cArgs = 0;
dp.rgvarg = NULL;

hr = pCOMAddIns->lpVtbl->Invoke(pCOMAddIns, dispID, &IID_NULL,
LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET | DISPATCH_METHOD, &dp,
&varRetVal, NULL, NULL);

COMAddInsCount = varRetVal.intVal;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top