The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: travism on May 17, 2009, 09:14:59 AM

Title: ChooseColor causes program to die.
Post by: travism on May 17, 2009, 09:14:59 AM
So I decided to use a choosecolor dialog box, mind you im using the newest headers from the goasm headers project. Here is my code, It doesnt give me any errors but when i click the button for it to show the colors dialog box it causes the program to exit with error.


DATA SECTION
           cColor  CHOOSECOLORA <?>            ; I have to choose CHOOSECOLORA or CHOOSECOLORW, or is it gives me a error.


          ............. The usual code here .....................

          cmp d[uMsg],WM_COMMAND
          jne >TRUE
                   cmp d[uMsg],IDC_CHOOSECOLORS
                    jne >FALSE

                            invoke ZeroMemory,addr cColor,sizeof(cColor)
                            mov     d[cColor.lStructSize],sizeof(cColor)
                            push    [hWnd]
                            pop      [cColor.hwndOwner]
                            mov      d[cColor.Flags],CC_PREVENTFULLOPEN
                           invoke  ChooseColor,addr cColor
          jmp >TRUE


Im guessing it has to do with how the structure was defined in the headers? or am I doing something wrong here?

EDIT: Sorry for the double post, internet is REALLY slow..
Title: Re: ChooseColor causes program to die.
Post by: travism on May 17, 2009, 12:52:52 PM
Even just tried creating a project by itself for it and it still errors :S Any thoughts?
Title: Re: ChooseColor causes program to die.
Post by: evlncrn8 on May 17, 2009, 03:12:13 PM
jne >TRUE

definately looks wrong to me
TRUE and FALSE are definitions, NOT labels
Title: Re: ChooseColor causes program to die.
Post by: PBrennick on May 17, 2009, 03:28:48 PM
As you have just been told, TRUE and FALSE should NOT be used as they will cause a brane to the value contained in them which is 1 or 0. Definitely not a good idea to redirect program execution to either of those addresses.

Paul
Title: Re: ChooseColor causes program to die.
Post by: travism on May 17, 2009, 03:52:38 PM
Well the labels arnt actually true and false but they lead to

xor eax,eax
ret


and


mov eax,1
ret


They have to divert flow for the dialog procedure to return true or false because there is no conditional assembly statements like if and then in goasm. :S unless im missing something here?
Title: Re: ChooseColor causes program to die.
Post by: Neil on May 17, 2009, 04:03:30 PM
What they are saying is that you must change the names of your LABELS to something other than TRUE or FALSE.
Title: Re: ChooseColor causes program to die.
Post by: travism on May 17, 2009, 04:56:36 PM
Oh I kinda thought that, I just put true or false to show what they were leading to sorry for that. I didn't know you HAVE to fill out the custom colors part of the structure so now it works... but it doesnt return an rgb value? what does the type return?
Title: Re: ChooseColor causes program to die.
Post by: Darrel on May 17, 2009, 10:05:21 PM
cColor.rgbResult contains the color selected if they exit with OK (returns nonzero). It is of the form 0x00bbggrr.

Regards,

Darrel
Title: Re: ChooseColor causes program to die.
Post by: travism on May 17, 2009, 11:10:20 PM
Im trying to write the results to a ini file but its just erasing the value:


invoke WritePrivateProfileString,addr IniKey,addr IniString,addr cColor.rgbResult,addr IniFile


doing something wrong?
Title: Re: ChooseColor causes program to die.
Post by: Darrel on May 17, 2009, 11:42:41 PM
Someone else can correct me if I'm wrong, but I believe you need to convert DWORD (CColor.rgbResult) to a string.
Title: Re: ChooseColor causes program to die.
Post by: travism on May 18, 2009, 05:54:59 AM
Ahh kind of figured that, I wish goasm had dwtoa, can't remember having to do this is there a easy way to do it?
Title: Re: ChooseColor causes program to die.
Post by: Darrel on May 18, 2009, 06:24:57 AM
DWORD_to_ASCII PROC dword0:DWORD,lpsz:DWORD
LOCAL tempbuffer[16]:BYTE
LOCAL dw10:DWORD
LOCAL posneg:BYTE

mov dw10,10
mov eax,dword0
xor ecx,ecx
or eax,eax
jns DWORD_to_ASCII_00000

neg eax
inc ecx

DWORD_to_ASCII_00000:

mov posneg,cl

push ebx
push edi

mov ebx,lpsz
lea edi,tempbuffer
xor ecx,ecx

DWORD_to_ASCII_00001:

xor edx,edx
div dw10
or dl,30h
mov BYTE PTR[edi+ecx],dl
inc ecx
or eax,eax
jnz DWORD_to_ASCII_00001

cmp posneg,0
je DWORD_to_ASCII_00002

mov BYTE PTR[ebx+eax],02Dh
inc eax

DWORD_to_ASCII_00002:

dec ecx
mov dl,BYTE PTR[edi+ecx]
mov BYTE PTR[ebx+eax],dl
inc eax
or ecx,ecx
jnz DWORD_to_ASCII_00002

mov BYTE PTR[ebx+eax],0

pop edi
pop ebx

ret

DWORD_to_ASCII ENDP
Title: Re: ChooseColor causes program to die.
Post by: donkey on May 18, 2009, 06:50:26 AM
No need to convert anything, use WritePrivateProfileStruct instead to write raw data to an INI file...

invoke WritePrivateProfileStruct, addr Section, addr IniKey, addr cColor.rgbResult, SIZEOF CHOOSECOLOR.rgbResult, addr IniFile

Quote from: travism on May 18, 2009, 05:54:59 AM
Ahh kind of figured that, I wish goasm had dwtoa, can't remember having to do this is there a easy way to do it?

It is apparently impolite to discuss GoAsm related questions in this forum...
Title: Re: ChooseColor causes program to die.
Post by: travism on May 18, 2009, 07:02:11 AM
Quote
It is apparently impolite to discuss GoAsm related questions in this forum...

Oh my bad thought it was a "general assembler" forum...  :-\ Thanks for the help :)

Edit: btw donkey it worked perfectly. :)
Title: Re: ChooseColor causes program to die.
Post by: xandaz on January 31, 2011, 10:16:25 PM
   I'm replying a late because i guess it might be important if someone else sees this topic. You definatelly need the 16*COLORREF array. I've experienced similar problems.
ClrRefs         dd      0ff0000h,0ff00h,0ffh,0ffff00h,0ffffh
                dd      0cc0000h,0cc00h,0cch,0cccc00h,0cccch
                dd      0800000h,08000h,080h,0808000h,08080h
                dd      0400000h

Thanks and bye
Title: Re: ChooseColor causes program to die.
Post by: dedndave on January 31, 2011, 11:57:09 PM
i got this table from MichaelW
it emulates the old CGA 16 color set, and thus, the first 16 default EGA/VGA values
CustomColors     dd 00000000h,00AA0000h,0000AA00h,00AAAA00h
                 dd 000000AAh,00AA00AAh,000055AAh,00AAAAAAh
                 dd 00555555h,00FF5555h,0055FF55h,00FFFF55h
                 dd 005555FFh,00FF55FFh,0055FFFFh,00FFFFFFh

Title: Re: ChooseColor causes program to die.
Post by: xandaz on February 01, 2011, 09:10:51 PM
   Thanks dave. That's something i didnt know. Ty and bye