If the component you are calling supports IDispatch(which is likely if it was created in VB), you can use late binding to dynamically call COM interface methods.
For instance:
IDispatch *pDispatch;
HRESULT hr = pUnknown->QueryInterface(IID_IDispatch, reinterpret_cast<void **>(&pDispatch));
if(SUCCEEDED(hr))
{
DISPID dispid;
hr = pDispatch->GetIDsOfNames(IID_NULL, &sMethodName, 1, LOCALE_SYSTEM_DEFAULT, &dispid);
if(SUCCEEDED(hr))
{
VARIANT vEmpty;
vEmpty.vt = VT_EMPTY;
DISPPARAMS dp = { &vt, 0, 0, 0 };
hr = pDispatch->Invoke(dispid, IID_INULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dp, 0, 0, 0);
}
pDispatch->Release();
}
This example retrieves the DISPIDspecified method from IDispatch::GetIDsOfNames(), then calls this method, passing DISPIDin IDispatch::Invoke().
For clarity, I suggested that there are no arguments for the method you want to call, but you can change the DISPPARAMSstructure that is passed Invoke(), if any.
source
share