ChooseColor

This is a discussion on ChooseColor within the Windows Programming forums, part of the Platform Specific Boards category; When I run the attached program and hit 0 on the numberpad, I get an error saying Project1.exe has caused ...

  1. #1
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269

    ChooseColor

    When I run the attached program and hit 0 on the numberpad, I get an error saying Project1.exe has caused an error in COMDLG32.dll. Earlier, before I made the CHOOSECOLOR structure global and had it in WndProc, I got the same error with KRNL386.exe. I've made several test programs using the same and different circumstances, and for the most part it just doesn't show up. I have gotten the COMDLG32.dll error again with a test with CHOOSECOLOR global.

    - SirCrono6
    Attached Files Attached Files
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I see you took Salem's advise.

    You should mention that you're using Windows ME. Perhaps it works under other versions of Windows.

    [edit]
    KRNL396.exe
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255
    It's pretty obvious that this wouldn't (or indeed shouldn't) work on any version of Windows. You can't just pass a CHOOSECOLOR structure without providing any information. You must ensure that at least the first member, the size of the structure, has been set. This member is important as Microsoft may well add members in the future and thus change the size, so older variants of the structure can be easily determined.
    Code:
    choosecolor.lStructSize = sizeof(choosecolor);
    Also, you should clear all the other members just in case they are referenced by the function. So, in all, you need to initialize it like this:-
    Code:
    ZeroMemory(&choosecolor, sizeof(choosecolor));
    choosecolor.lStructSize = sizeof(choosecolor);
    For a working example of the Choose Color Dialog, please read this.
    Last edited by SMurf; 11-21-2005 at 01:44 PM. Reason: D'oh, it's lStructSize, not cbSize. Why can't M$ be consistent...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ChooseColor()
    By Elyubarov in forum Windows Programming
    Replies: 1
    Last Post: 04-08-2005, 11:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21