Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Window Creation Crash...

SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
Alright, I've been creating windows for several years now, and using this same class in my past few apps, but with my new app, it crashes on the 'CreateWindow()' check. The class registers fine, so here's the problematic line.
[code]
#define WINDOW_TITLE "Diablo II Level Format Editor"
#define WINDOW_CLASS "Diablo_Class"
#define WINDOW_CALLBACK "MainCalls"

bool WINDOWDATA::CreateWin()
{
MessageBox(NULL, "Create", "Debug", MB_OK);
if((Handle = CreateWindow(WINDOW_CLASS, WINDOW_TITLE, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 512, 384, NULL, NULL, Instance, NULL)) == NULL)
{
MessageBox(NULL, "Could not create the main window.", "Startup Error", MB_OK | MB_ICONSTOP);
return false;
}

return true;
}
[/code]
Instance is set to the 'HINSTANCE' the 'WinMain()' function passes, so it should be OK also. Thanks for the help!

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Comments

  • bikibiki Member Posts: 492
    [green]
    Its difficult to tell, there could be many reasons.
    There are many types of "crashes". What error message are you getting?


    Also, just curious, why do you add a "" at the end of a string literal as you did in: 'MessageBox(NULL, "Create", "Debug", MB_OK);' ?
    [/green]
    : Alright, I've been creating windows for several years now, and using this same class in my past few apps, but with my new app, it crashes on the 'CreateWindow()' check. The class registers fine, so here's the problematic line.
    : [code]
    : #define WINDOW_TITLE "Diablo II Level Format Editor"
    : #define WINDOW_CLASS "Diablo_Class"
    : #define WINDOW_CALLBACK "MainCalls"
    :
    : bool WINDOWDATA::CreateWin()
    : {
    : MessageBox(NULL, "Create", "Debug", MB_OK);
    : if((Handle = CreateWindow(WINDOW_CLASS, WINDOW_TITLE, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 512, 384, NULL, NULL, Instance, NULL)) == NULL)
    : {
    : MessageBox(NULL, "Could not create the main window.", "Startup Error", MB_OK | MB_ICONSTOP);
    : return false;
    : }
    :
    : return true;
    : }
    : [/code]
    : Instance is set to the 'HINSTANCE' the 'WinMain()' function passes, so it should be OK also. Thanks for the help!
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :

    [hr][red]~Bikram[/red]

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    [b][red]This message was edited by AsmGuru62 at 2004-4-10 5:21:16[/red][/b][hr]
    [b][red]This message was edited by AsmGuru62 at 2004-4-10 5:20:31[/red][/b][hr]
    [blue]Make sure your callback returns zero on WM_CREATE. Also, put a breakpoint on the callback and track all which comes BEFORE WM_CREATE and consult MSDN on the return values. Basically, DefWindowsProc takes care of that, but do it anyway... also, if the callback not too big - post its code here in full.[/blue]
    : [green]
    : Its difficult to tell, there could be many reasons.
    : There are many types of "crashes". What error message are you getting?
    :
    :
    : Also, just curious, why do you add a "" at the end of a string literal as you did in: 'MessageBox(NULL, "Create", "Debug", MB_OK);' ?
    : [/green]
    : : Alright, I've been creating windows for several years now, and using this same class in my past few apps, but with my new app, it crashes on the 'CreateWindow()' check. The class registers fine, so here's the problematic line.
    : : [code]
    : : #define WINDOW_TITLE "Diablo II Level Format Editor"
    : : #define WINDOW_CLASS "Diablo_Class"
    : : #define WINDOW_CALLBACK "MainCalls"
    : :
    : : bool WINDOWDATA::CreateWin()
    : : {
    : : MessageBox(NULL, "Create", "Debug", MB_OK);
    : : if((Handle = CreateWindow(WINDOW_CLASS, WINDOW_TITLE,
    WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 512, 384, NULL,
    NULL, Instance, NULL)) == NULL)
    : : {
    : : MessageBox(NULL,
    "Could not create the main window.", "Startup Error",
    MB_OK | MB_ICONSTOP);
    : : return false;
    : : }
    : :
    : : return true;
    : : }
    : : [/code]
    : : Instance is set to the 'HINSTANCE' the 'WinMain()' function passes, so it should be OK also. Thanks for the help!
    : :
    : : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    : :
    :
    : [hr][red]~Bikram[/red]
    :
    :





  • SephirothSephiroth Fayetteville, NC, USAMember Posts: 1,035
    : [b][red]This message was edited by AsmGuru62 at 2004-4-10 5:21:16[/red][/b][hr]
    : [b][red]This message was edited by AsmGuru62 at 2004-4-10 5:20:31[/red][/b][hr]
    : [blue]Make sure your callback returns zero on WM_CREATE. Also, put a breakpoint on the callback and track all which comes BEFORE WM_CREATE and consult MSDN on the return values. Basically, DefWindowsProc takes care of that, but do it anyway... also, if the callback not too big - post its code here in full.[/blue]
    : : [green]
    : : Its difficult to tell, there could be many reasons.
    : : There are many types of "crashes". What error message are you getting?
    : :
    : :
    : : Also, just curious, why do you add a "" at the end of a string literal as you did in: 'MessageBox(NULL, "Create", "Debug", MB_OK);' ?
    : : [/green]
    I'll post the code later, I'm heading to work shortly. I did want to say that I add the null-terminator because you're supposed to null-terminate the strings used in message boxes according to the MSDN. I've been doing it not only in static strings like those, but also in actual buffers I use in them. Oh, and I didn't have WM_CREATE set to return zero, so that may be the issue. It just passes the info to 'DefWindowProc()' at this point in time. I'll adjust it tonight.

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : I'll post the code later, I'm heading to work shortly. I did want to say that I add the null-terminator because you're supposed to null-terminate the strings used in message boxes according to the MSDN. I've been doing it not only in static strings like those, but also in actual buffers I use in them. Oh, and I didn't have WM_CREATE set to return zero, so that may be the issue. It just passes the info to 'DefWindowProc()' at this point in time. I'll adjust it tonight.
    :
    : -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
    :
    :

    [blue]If you pass the WM_CREATE to do default stuff - should be fine...
    You should know that '' (so called null-terminator) is added to a string in quotes automatically, so if you use somewhere "text" - this is already terminated. You just adding one extra-symbol in every string - for the final memory image - it can't be that bad. You do not have million string in quotes (so you will lose 1 Mbyte) - are you? If you have a "text" - you simply have two null-terminators at the end - the one you put and the one compiler puts there by default.
    [/blue]

Sign In or Register to comment.