怎样取得某一成员函数的地址?

xirumin 2007-11-15 03:29:10
某个类CInitApp, 其中有个成员函数
int CALLBACK CInitApp::DoSomthing(int,LPSTR)
{
.....
}

另一个函数, 需要传递上个函数的地址, 这个地址是十六进制的DOWRD型, CInitApp::NeedAddress(DWORD FuncAddress).

假如DoSomething的地址是0X0044BD5C, 那么希望最后调用时是这样
NeedAddress(0X0044BD5C); //调用函数

这个怎么写?
...全文
149 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
superarhow 2007-11-15
  • 打赏
  • 举报
回复
NeedAddress((DWORD)&PFunc); ////这样虽能通过, 但传递进去的是PFunc的地址
已经很接近了,NeedAddress(*(DWORD)&PFunc);不就行了么
MLiang 2007-11-15
  • 打赏
  • 举报
回复
1. printf("%b")

2. 顶楼上的
Yofoo 2007-11-15
  • 打赏
  • 举报
回复
#define GET_FUN(_Fun) ((VOID *)(&(DWORD &)(_Fun)))

GET_FUN(DoSomthing)
stivenjia 2007-11-15
  • 打赏
  • 举报
回复
DWORD dwS = 0;
_asm
{
xor eax,eax
mov eax,Me
mov ebx,dword ptr[dwS]
mov ebx,eax
}
不知道这么做对不对
chehw 2007-11-15
  • 打赏
  • 举报
回复
将DoSomthing声明为静态类成员函数

NeedAddress((DWORD)CInitApp::DoSomething); //32位下可以,64位系统会有问题
yxz_lp 2007-11-15
  • 打赏
  • 举报
回复
NeedAddress((DWORD)CInitApp::DoSomething); //看看
xirumin 2007-11-15
  • 打赏
  • 举报
回复
我是这样写的, 编译通不过
typedef int (int CALLBACK *pf)(int,LPSTR);
pf PFunc=&CInitApp::DoSomething;
NeedAddress((DWORD)PFunc); ////这句话通不过
NeedAddress((DWORD)&PFunc); ////这样虽能通过, 但传递进去的是PFunc的地址
NeddAddress((DWORD)*PFunc); ////这样也通不过

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧