Thread: Odd program crashes

  1. #1

    Odd program crashes

    I'm getting all sorts of weird errors thrown at me ... I think it may be to do with the size of my struct, is there only a limited size for them???

    typedef struct {
        /* Menu specifics */
        int iStyle;       //Style
        int iMode;        //Mode
        int iItems;       //Number of items
        int iType;        //Item types
        int iCaptions;    //Item captions
        int iOverflowX;   //X-Axis overflow
        int iOverflowY;   //Y-Axis overflow
        bool bDocked;     //Is it docked?
        bool bSet;        //Is it set?
        HBITMAP *hBmps;   //Bitmaps (if bmp mode)
        HICON *hIcons;    //Icons (if icon mode)
        LPSTR *lCaptions; //Captions
        /* Theme related */
        COLORREF cFace;
        COLORREF cFrame;
        COLORREF cText;
        COLORREF cCaption;
        HBITMAP hChevron;
        HBITMAP hClose;
        HBITMAP hCstmBtn;
    In my window procedure (this is a custom control) I set most things to defaults on WM_CREATE, if I comment out setting the cFACE and cCaption COLORREF variables it doesn't crash but if they are uncommented it does crash.

    I set them like lpms->cFace = RGB(255,0,0) where lpms is MENUSTRUCT*..

    Also in my struct could I replace HBITMAP* and HICON* with HANDLE* ??? I could use one variable then because it's either using icons or bitmaps, not both.

  2. #2
    Post the errors.

    There's no size restriction on a struct.

    This may seem like a silly question, but does your lpms pointer point to a valid memory location? i.e. have you allocated it with a call to new and did your call to new return successfully?
    "There's always another way"
    -lightatdawn (

  3. #3
    Yes, in the WM_CREATE I allocate memory for it and test it for NULL ...

    I get that application has encountered a problem and needs to close error and you can send and error report or whatever (on xp) ...

    I tried using GDB debugger thingy but all it does is tell me it raised a segmentation fault or something.. Which sort of leads me to believe that it's trying to access or set it or something after it's memory is gone but I'm not sure if that's right and if it is how I can stop it.

    I have also allocated the required space when registering the window class.

  4. #4
    train spotter
    Join Date
    Aug 2001
    near a computer
    Just an idea....

    Sounds like a mem access problem. You using mem that is not realy yours.
    If COLORREF cFace is the problem I would look at how you use, alloc mem ect for the elements above it. In my experience you are making a mistake with one of them. Check the value in cFace does not change unexpectedly (put a break point in each place you use it).

    >>Yes, in the WM_CREATE I allocate memory for it and test it for NULL ...

    Is the pointer a static or global ect?

    That is how do you ensure the pointer to the struct has scope for the entire app and does not become dangling?
    Any var declared in a callback only has scope for a single messsage, not the 'life' of the app.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd issue with program
    By TigerTank77 in forum C Programming
    Replies: 8
    Last Post: 05-12-2009, 12:00 AM
  2. funcion runs 14 times, then program crashes
    By happyclown in forum C Programming
    Replies: 9
    Last Post: 03-03-2009, 11:58 PM
  3. Help C program that reads Odd numbers and evens
    By Cyberman86 in forum C Programming
    Replies: 4
    Last Post: 02-27-2009, 11:59 AM
  4. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  5. My I/O Program crashes, I need some help
    By Guti14 in forum C Programming
    Replies: 4
    Last Post: 09-24-2004, 01:16 AM