high6 Posted December 20, 2008 Posted December 20, 2008 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 .
Killboy Posted December 20, 2008 Posted December 20, 2008 (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 December 20, 2008 by Killboy
high6 Posted December 20, 2008 Author Posted December 20, 2008 I know about the calling conventions . Just seems messy with typedefs.
atom0s Posted December 20, 2008 Posted December 20, 2008 (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 December 20, 2008 by Atomos
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now