C++ - 指向类方法的指针
我必须设置一个指向库函数 (IHTMLDocument2::write
) 的指针,该函数是 IHTMLDocument2
类的方法。 (出于好奇:我必须用 Detours 来挂钩该函数)
我不能直接执行此操作,因为类型不匹配,我也不能使用强制转换(reinterpret_cast<>
这是“正确的”一”afaik 不起作用)
这就是我正在做的:
HRESULT (WINAPI *Real_IHTMLDocument2_write)(SAFEARRAY *) = &IHTMLDocument2::write
感谢您的帮助!
I have to set up a pointer to a library function (IHTMLDocument2::write
) which is a method of the class IHTMLDocument2
. (for the curious: i have to hook that function with Detours)
I can't do this directly, because of type mismatch, neither can I use a cast (reinterpret_cast<>
which is the "right one" afaik doesn't work)
Here's what I am doing:
HRESULT (WINAPI *Real_IHTMLDocument2_write)(SAFEARRAY *) = &IHTMLDocument2::write
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指向函数的指针具有以下类型:
如您所见,它由其类名限定。它需要一个类的实例来调用(因为它不是静态函数):
The pointer to function has the following type:
As you can see, it's qualified with it's class name. It requires an instance of a class to call on (because it is not a static function):
您需要使用成员函数指针。普通的函数指针不起作用,因为当您调用(非静态)类成员函数时,有一个隐式的 this 指针引用该类的实例。
You need to use a member function pointer. A normal function pointer won't work, because when you call a (non-static) class member function there is an implicit
this
pointer referring to an instance of the class.