Posted December 20, 200816 yr 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 .
December 20, 200816 yr 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, 200816 yr by Killboy
December 20, 200816 yr 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, 200816 yr by Atomos
Create an account or sign in to comment