Are there any caveats to using the esi and edi registers as "general purpose" registers on Windows9x? This snippet of code in one of my programs works perfectly on Windows NT but on Windows 98 it freaks the computer out so bad that it reboots itself:

movePosY dd 0


HideMsgWindow proc hWnd:HWND

invoke KillTimer, hWnd, WM_TIMER_MSGWINDOW
invoke KillTimer, hWnd, WM_TIMER_RAISEWINDOW

invoke GetWindowPlacement, hWnd, ADDR wp
mov edi,
mov movePosY, edi

invoke SetTimer, hWnd, WM_TIMER_LOWERWINDOW, windowSpeed, NULL

xor eax, eax

HideMsgWindow endp

If I change the code to use eax or ecx as the temporary holding place instead of edi, the program works fine on Windows 98. This is a mystery to me because I thought esi/edi were general purpose, and I use them as such in other places with no ill effects.
Posted on 2002-03-25 14:20:56 by rdaneel
always preserve ebx, esi and edi in any callback or window procs and you won't have any problems, promise ;)
Posted on 2002-03-25 14:35:11 by Tola

always preserve ebx, esi and edi in any callback or window procs and you won't have any problems, promise ;)

and ebp, too, right?
Posted on 2002-03-25 17:36:23 by jademtech

The Windows convention is simple, if you use ANY of EBX, ESI or EDI, you preserve them in a procedure. ESP and EBP are normally used for entry and exit to procedures and you must preserve both if you handle the procedure manually.

The interesting part is that it has NOTHING to do with a callback or message handling proc at all. If either do not use EBX, ESI and EDI, you do NOT need to preserve them.

When you write your own procedures, just check what registers you use and if you use any of EBX, ESI and EDI, preserve them in the right order.

Posted on 2002-03-25 18:20:20 by hutch--
I'd be interested to know exactly what it is that Windows does with those registers and why MS has made it so essential that you preserve them.
Posted on 2002-03-25 19:55:25 by iblis
Its just the windows calling convention. Its just means that a procedure that is operating on top of code that is not yours, be it in a DLL, a Callback etc, has to preserve these registers.

EBX ESI EDI do not have a definate value. But it doesn't mean you cannot use then in your program.

It just means that you can depend on these registers to be unchanged in your program if you call another API (unless specified otherwise), and likewise, if another piece of code calls your API it can depend on those registers been unchaged.

Posted on 2002-03-26 02:26:00 by huh
I was watching the registers while they came
into one of my wndprocs. I was trying to find
a way of getting the thread stack pointers and
I noticed a pattern. When the ebx, ebp are equal
it also equals your stack pointer (esp). There
are other patterns, try it.

It is strange, GetMessage and SendMessage change
everything but the ebx, and MoveWindow seems to
change everything.

Is there a reference list somewhere?:rolleyes:
Posted on 2002-03-26 02:48:17 by bdjames
You cannot depend on those register values...
Posted on 2002-03-26 07:43:27 by f0dder