Hi CommonTater,
A function specified with the __declspec(naked) convention does not have a stack frame created automatically by the compiler. You need to manipulate yourself the stack to access parameters. Here is a quick example :
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
__declspec(naked) char* UpperCase(char* szText) /* Turn off framing to get
a smaller sized function */
{
__asm{
mov eax,[esp+4] /* get the address of the string to be converted */
sub eax,1
__repeat:
add eax,1
movzx ecx,BYTE PTR [eax]
test ecx,ecx
je __end
cmp ecx,97 /* if ASCII(ecx) < 97 then ignore the charater */
jb __repeat
cmp ecx,122 /* if ASCII(ecx) > 122 then ignore the charater */
ja __repeat
sub BYTE PTR [eax],32 /* convert lowecase to uppercase */
jmp __repeat
__end:
mov eax,[esp+4]
ret 4 /* balance manually the stack */
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
char msg[]="inline assembly programming";
MessageBox(0,UpperCase(msg),"Hello!",MB_OK);
return 0;
}
EDIT : Manual stack balancing with RET 4