News:

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

ChooseColor causes program to die.

Started by travism, May 17, 2009, 09:14:59 AM

Previous topic - Next topic

travism

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..

travism

Even just tried creating a project by itself for it and it still errors :S Any thoughts?

evlncrn8

jne >TRUE

definately looks wrong to me
TRUE and FALSE are definitions, NOT labels

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

travism

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?

Neil

What they are saying is that you must change the names of your LABELS to something other than TRUE or FALSE.

travism

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?

Darrel

cColor.rgbResult contains the color selected if they exit with OK (returns nonzero). It is of the form 0x00bbggrr.

Regards,

Darrel

travism

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?

Darrel

Someone else can correct me if I'm wrong, but I believe you need to convert DWORD (CColor.rgbResult) to a string.

travism

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?

Darrel

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

donkey

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...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

travism

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. :)

xandaz

   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