Jump to content
Tuts 4 You

Call c++ member function through asm


urbanyoung

Recommended Posts

Posted

Hey,

I'm trying to call a c++ class member function through asm. I believe the this param (class id) is passed using ECX in the function call, getting this is no problem. However, when I call the function (with the class id in ECX) the function doesn't crash like before, but it returns incorrect data. I was wondering if anything else needs to be passed to the function or if ECX is infact the class id used to associate data with the caller. Any tips would be appreciated.

Posted

If you are getting incorrect data, make sure your params are correct and that you are passing the proper pointer into ECX. As mudlord said, you can do inline ASM inside of C++ using _asm / __asm tags. For calling a class member function something on the line of this should work:

_asm {
push param3
push param2
push param1
lea ECX, [class_ptr]
call member_ptr
}

I'm not great with ASM so don't rely on that to work as I can only give you my assumption. Class calls in C++ internally are done as:

result class::function( class_ptr, param1, param2, param3, ... )

Some good reads about some of this topic:
/>http://www.codeguru.com/cpp/misc/misc/assemblylanguage/article.php/c14641/
/>http://www.codeguru.com/cpp/v-s/tips/debugging/article.php/c14681/
/>http://www.codeguru.com/cpp/v-s/debug/openfaq/article.php/c14799/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...