In the example of calling function assembly, you should note that the on-site method of restoring the stack (the value of the top pointer of the ESP stack) after the call is not restored, or the recovery is incorrect, A large error is reported!
// Call a function without Parameters
DWORD dwret;
Void callfunc0 (lpvoid lpfunc)
{
_ ASM
{
Call dword ptr [lpfunc]
MoV dwret, eax
// CMP ax, 1 // [esp + 4]
// Call dword ptr [lpfunc]
}
}
// Call a Parameter Function
Void callfunc1 (lpvoid lpfunc, DWORD param1)
{
_ ASM
{
Push param1
Call DWORD Ptr [lpFunc]
Add esp, 4 // resume the stack pointer
Mov dwRet, eax
}
}
// Call a function with two parameters
Void CallFunc2 (LPVOID lpFunc, DWORD param1, DWORD param2)
{
_ Asm
{
Push param1
Push param2
Call DWORD Ptr [lpFunc]
Add esp, 8 // resume the stack pointer
Mov dwRet, eax
}
}
// Call functions with three parameters
Void CallFunc3 (LPVOID lpFunc, DWORD param1, DWORD param2, DWORD param3)
{
_ Asm
{
Push ax
Call DWORD Ptr [lpFunc]
Cmp ax, [A esp-4]
Call DWORD Ptr [lpFunc]
Mov dwRet, eax
}
}
Void func0 ()
{
: MessageBox (0, 0, 0, 0 );
}
Void func1 (LPCTSTR lpStr)
{
: MessageBox (0, lpStr, 0, 0 );
}
Void func2 (maid, maid)
{
: MessageBox (0, lpstr, lpstr2, 0 );
}
// Start the call here
Void onbnclickedok ()
{
// Todo: add your control notification handler code here
Dwret = 0;
Callfunc0 (func0 );
Lpctstr lp1 = _ T ("Call func1 called !~ ");
Callfunc1 (func1, (DWORD) lp1 );
Lpctstr lp2 = _ T ("Call func2 called !~ ");
Callfunc2 (func2, (DWORD) lp1, (DWORD) lp2 );
}