Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++: InvokeHelper() function

I am deciphering a huge project that uses COM, which I am completely new to. It's quite confusing and I can't figure out how everything interacts. All I see is InvokeHelper(...) where I would expect to see a big amount of code. What is InvokeHelper()? What does it do? Thank you for any help.

like image 695
John Avatar asked Feb 24 '23 06:02

John


1 Answers

Even though it's a late answer, I'd like to post it here as I have spent a couple of days to figure out how it's working. It may be interesting for someone else.

Below is the path how to get to the real code from InvokeHelper() call:

  1. InvokeHelper() should be called for an object of a class, inherited from CWnd with DISPID specified, where DISPID is something like 0x00000261
  2. The class should have inside a call to a method CreateControl() with a GUID of a COM class
  3. The COM class with the GUID should be COM coclass with at least one IDL interface
  4. The IDL interface should implement a method with the attribute [id(DISPID)]. This is the same DISPID as in item 1
  5. Look for implementation of the interface and find the method with this id attribute
  6. Voilà!

Sure, if you don't have a source code of the COM class with the CLSID you cannot take a look inside the method, but at least, you can find its name as follows:

DISPID dispidCommand = 0x1; /// This is the dispid, you're looking for

COleDispatchDriver driver;
BOOL bRes = driver.CreateDispatch(GetClsid());
ASSERT(bRes);

HRESULT hr;
CComPtr<ITypeInfo> pti;
hr = driver.m_lpDispatch->GetTypeInfo(0, GetUserDefaultLCID(), &pti);
ASSERT(SUCCEEDED(hr));

UINT nCount = 0;
CComBSTR bstrName;  // Name of the method, which is called via DISPID
hr = pti->GetNames(dispidCommand, &bstrName, 1, &nCount);
ASSERT(SUCCEEDED(hr)); 

I hope it helps someone. Take care.

like image 93
Anton K Avatar answered Feb 26 '23 19:02

Anton K