Using inline assembly from C ++
Just to experiment with building in C ++, I tried the following, which caused the application to crash:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
__asm {
push 5000
call Sleep
}
...
}
the assembly part of the code should act like the following line
Sleep(5000);
What am I doing wrong?
edit: I am getting an access violation.
+2
source to share
4 answers
It's been a long time since I did this, but I remember from the past that sometimes I had to inject a single parameter into the EAX register instead of pushing it onto the stack. Or perhaps you need to pop out again after words if convention requires it.
As Arak says, make sure you follow the compiler calling convention. Masm will supplant one convention, check your C compiler enforces.
0
source to share