您的位置:首页 > 其它

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

2013-09-24 15:16 204 查看
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 到底是怎么做到的需要追寻一下源码实现。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: