-
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???
Code:
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;
}MENUSTRUCT, *lpMENUSTRUCT;
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.
-
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?
-
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.
-
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.