Author Topic: Inline assembly and calling API functions  (Read 291 times)

Vortex

  • Moderator
  • Member
  • *****
  • Posts: 2657
Inline assembly and calling API functions
« on: February 28, 2022, 01:06:44 AM »
In the inline asm block, the API function MessageBox should be enclosed between square brackets otherwise wrong call to API will lead to application crash :

Code: [Select]
// Source code built with PellesC 11.00.2

#include <stdio.h>
#include <windows.h>
char t1[]="This is a test1.";
char t2[]="This is a test2.";

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, WCHAR *pszCmdLine, int nCmdShow)
{
__asm{

push 0
push OFFSET t1
push OFFSET t1
        push 0
call DWORD PTR [MessageBox]
}

MessageBox(0,t2,t2,0);
return 0;
}