关于成员函数指针和普通函数指针的转换

http://bbs.csdn.net/topics/10251675

查看九楼zdhe的回复。

a function call like following
p->func(100);   // it will return nothing.
in C++ will be compiled to like following

  push        64h   //push parameter one by one. c++ always use ESP to pass parameter, because ECX is used for 

//THIS pointer. there is no fastcall standard for C++
  mov         edx,p    
  mov         eax,dword ptr [edx]   //save vtable to eax
  mov         ecx,p    // __this call standard ask compiler to save class poiner to ecx.
  call        dword ptr [eax+4]    //it's func1 address, if must func, maybe [eax + 8],....


Have you got any idea?
so before get pointer , just do like following:

wait a common test func and see asmemble code ( for pi->play) , you will know shift 
[eax + n]   (n is waht you want .)

COM interface make sure this number will never change any more(else the caller program need rebuild ..hehe)

so 

_asm{
  mov         edx,pi    
  mov         eax,dword ptr [edx]   
  mov         eax , [eax + n]    //n is fix for you know.
}

then here, eax hold you p->Play ....

从汇编语言层面上证明了不可能直接进行转换。

不过boost::function 和 boost::bind 到底是怎么做到的需要追寻一下源码实现。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值