Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I created a MFC dialog based app in VS2008 in Windows7 64bit. I placed some asm code:

C++
void CMfcAsmTestDlg::OnBnClickedButton1()
{
  char format[] = "%s %s\n";
  char hello[] = "Hello";
  char world[] = "world";

   __asm
   {
      mov  eax, offset world
      push eax
      mov  eax, offset hello
      push eax
      mov  eax, offset format
      push eax
      call printf
      //clean up the stack so that main can exit cleanly
      //use the unused register ebx to do the cleanup
      pop  ebx
      pop  ebx
      pop  ebx
   }
}
I get: error C2415: improper operand type. This happens on each line I used the word 'mov'.

Do I need to change any project settings or include any file?
Posted
Updated 9-Aug-11 0:58am
v3

1 solution

This is because register eax accepts only long int types:
C++
void OnBnClickedButton1()
{
  char buff[256];
  char format[] = "%s %s\n";
  char hello[] = "Hello";
  char world[] = "world";
  unsigned int  f = (unsigned int)format,
                h = (unsigned int)hello,
                w = (unsigned int)world,
                b = (unsigned int)buff;

   __asm
   {
      mov  eax, w
      push eax
      mov  eax, h
      push eax
      mov  eax, f
      push eax
      mov  eax, b
      push eax
      call sprintf
      //clean up the stack so that main can exit cleanly
      //use the unused register ebx to do the cleanup
      pop  ebx
      pop  ebx
      pop  ebx
      pop  ebx
   }
}

Regards.
 
Share this answer
 
Comments
Mizan Rahman 9-Aug-11 7:16am    
Thanks. it worked. I actually got the code from http://msdn.microsoft.com/en-us/library/y8b57x4b(v=VS.90).aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900