![](/img/trans.png)
[英]How to get address of member function within the class without using class name for scope?
[英]how to get the address of a member function within a class
我正在尝试获取成员函数的地址。 基本上,我试图获取内存中加载的Windows api函数与我的函数之间的偏移量。
这是我尝试获取的地址:
NTSTATUS (NTAPI myntquerydirectoryfile)(
HANDLE hFile,
HANDLE hEvent,
PVOID pApcRoutine,
PVOID pApcContext,
IO_STATUS_BLOCK* ioStatus,
PVOID pBuffer,
ULONG bufferSize,
FILE_INFORMATION_CLASS infoClass,
BOOLEAN singleEntry,
PUNICODE_STRING pFileName,
BOOLEAN restart
)
{
cout << "my func" << endl;
};
typedef NTSTATUS (*pmyhook)(HANDLE hFile,
HANDLE hEvent,
PVOID pApcRoutine,
PVOID pApcContext,
IO_STATUS_BLOCK* ioStatus,
PVOID pBuffer,
ULONG bufferSize,
FILE_INFORMATION_CLASS infoClass,
BOOLEAN singleEntry,
PUNICODE_STRING pFileName,
BOOLEAN restart);
pmyhook = &myntquerydirectoryfile;
此代码快照展示了如何获取类成员函数的地址:
#include <stdio.h>
class A
{
public:
void test()
{
// Address of member function test(), is the value of &A::test
printf("Address of function is: 0x%X\n", &A::test);
}
};
int main()
{
A a;
a.test();
}
通常,不允许这样做,不建议这样做。
void (Class_Name::* FuncPointer)() = &Class_Name::Func_Name;
FuncPointer
将指向类方法。
最好在C ++ 11中使用静态函数或lambda功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.