Jump to content
Tuts 4 You

Best way to call local methods?


high6

Recommended Posts

Posted

What is the best way in C++ to call a method?

Current I am doing.

const int Method_Addr = 0x1234;

void Method()

{

__asm

{

call Method_Addr

}

}

Any suggestions? Thanks :D .

Posted (edited)

Best way would be to define a function pointer:

typedef int (__stdcall * ProcPtr)(char * Somestring, int SomeVal);

You can also leave out the var names if you want...

Now define a ProcPtr, assign the address and call it:

ProcPtr Function1;Function1 = (ProcPtr)0x1234;int RetVal = Function1("high6", 666);

Be sure youre using the right calling convention, this is crucial :)

stdcall would be the choice for windows api and most sdk callbacks

sometimes it's fastcall or something totally different (code optimization can affect this a lot)

Edited by Killboy
Posted

I know about the calling conventions :D .

Just seems messy with typedefs.

Posted (edited)
call dword ptr [variable]

Would be the more "proper" inline method, and in some cases is required. However I do agree with Killboy, the better way would be to use typedefs.

Edited by Atomos

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...