关于成员函数指针和普通函数指针的转换
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 到底是怎么做到的需要追寻一下源码实现。
查看九楼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 到底是怎么做到的需要追寻一下源码实现。
相关文章推荐
- c++ 成员函数 普通函数指针转换
- C++学习之普通函数指针与成员函数指针
- C++学习之普通函数指针与成员函数指针
- C++学习之普通函数指针与成员函数指针
- ads中关于函数指针转换的很奇怪的问题
- C++普通函数指针与成员函数指针实例解析
- C++普通函数指针与成员函数指针实例解析
- 普通函数指针与成员函数指针
- 关于指针作为函数参数传递的理解,对比普通变量作为函数参数的需注意点,其实就是行参和实参的问题。
- 关于函数指针类型强制转换的一些摸索
- [Reprint]C++普通函数指针与成员函数指针实例解析
- 使用std::function 把类成员函数指针转换为普通函数指针
- 12-4-26关于普通函数指针,类成员函数指针,char(*)[]
- 普通函数指针和指向成员函数指针(转载)
- 使用std::function 把类成员函数指针转换为普通函数指针
- 成员函数指针:(结构+与普通函数指针之间的转换)
- C++学习之普通函数指针与成员函数指针
- C++类成员函数指针使用实例——关于this指针的处理
- 封装回调函数——为对象方法(Object Method,参数中带this指针的函数) 构造 普通函数(参数中无this指针的函数)形式 的入口
- 关于函数的指针传递