Visual C++:InvokeHelper() 函数

发布于 2024-11-06 06:07:36 字数 133 浏览 1 评论 0原文

我正在破译一个使用 COM 的巨大项目,而我对此完全陌生。这很令人困惑,我无法弄清楚一切是如何相互作用的。我所看到的只是 InvokeHelper(...) ,我希望在其中看到大量代码。什么是InvokeHelper()?它有什么作用? 感谢您的帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独闯女儿国 2024-11-13 06:07:36

尽管这是一个迟到的答案,但我想将其发布在这里,因为我花了几天的时间来弄清楚它是如何工作的。对于其他人来说可能很有趣。

下面是如何从 InvokeHelper() 调用获取实际代码的路径:

  1. 应该为类的对象调用 InvokeHelper(),该类的对象继承自 CWnd,并指定了 DISPID,其中 DISPID 类似于 0x00000261
  2. 该类应该在调用内部具有 COM 类 GUID 的 CreateControl() 方法 具有
  3. GUID 的 COM 类应该是具有至少一个 IDL 接口的 COM 组件
  4. 类 IDL 接口应该实现具有属性 [id(DISPID)] 的方法。这与第 1 项中的 DISPID 相同。
  5. 查找接口的实现并找到具有此 id 属性的方法
  6. Voilà!

当然,如果您没有带有 CLSID 的 COM 类的源代码,您就无法查看该方法的内部,但至少,您可以找到其名称,如下所示:

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

我希望它对某人有所帮助。
小心。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文