Call methods of call Functions

Source: Internet
Author: User

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 );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.