News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

SetTextColor return values

Started by UtillMasm, December 05, 2009, 11:47:31 AM

Previous topic - Next topic

UtillMasm

 :eek
i hate protect my ECX before INVOKE SetTextColor.
invoke SetTextColor,HandleOfDC,Color
then return values:eax
ecx

What is mean the ECX value?

jj2007

Quote from: UtillMasm on December 05, 2009, 11:47:31 AM
:eek
i hate protect my ECX before INVOKE SetTextColor.
invoke SetTextColor,HandleOfDC,Color
then return values:eax
ecx

What is mean the ECX value?

QuoteIf the function succeeds, the return value is a color reference for the previous text color

Return value is always eax, unless explicitly specified differently. Ecx and edx are usually garbage, i.e. the OS uses them for own purposes and doesn't bother to save the original values.

UtillMasm


jj2007

Quote from: UtillMasm on December 05, 2009, 12:43:20 PM
:U
ECX is garbage.

... if coming out of a Window API. Otherwise, it's a versatile register that has a specific role in instructions such as rep xxx, jecxz, loopz etc.; that's why I chose to preserve it in MasmBasic. It is a matter of taste, eh, convention, and those who invented the ABI chose to trash it. Bad luck. If you need a workaround:

invapi MACRO api, args:VARARG
  push ecx
  push edx  ; optional. Per push/pop pair, count 2 bytes and 1-2 cycles
  ifb <args>
call api
  else
invoke api, args
  endif
  pop edx
  pop ecx
ENDM


Usage:
start:
mov ecx, 123
mov edx, 456
invapi GetTickCount
push edx   ; print trashes ecx and edx, too...
print str$(ecx), " "
pop edx
print str$(edx), 13, 10

mov ecx, 123
mov edx, 456
invapi Sleep, 1000
push edx
print str$(ecx), " "
pop edx
print str$(edx), 13, 10


sinsi

When you call an API there are registers that are preserved - EBX,ESI,EDI,EBP - and those that are trashed (undefined) - ECX,EDX.
Trashed as well is EAX if the API call doesn't return a value (but that's pretty rare).

This means that if you have a callback function you need to preserve the same registers windows does - EBX,ESI,EDI,EBP. I'm pretty sure this includes your window procedure.
Light travels faster than sound, that's why some people seem bright until you hear them.

UtillMasm

 :U

i really love jj's Incredible MACRO Functions.

JJ:

sir, when you release RichMasm source? :wink