Pointers, casting, SetGetWindowLong problem...

Bill Baxter dnewsgroup at billbaxter.com
Fri Mar 9 15:44:52 PST 2007


Chris Warwick wrote:
> Hi, i use this to create and show my window
> 
>             HINSTANCE hinstance = GetModuleHandleA(null);
>             fhandle = CreateWindowExA(
>                 WS_EX_APPWINDOW, "CjWindow", "Testing 123", WS_TILEDWINDOW,
>                 x, y, width, height, HWND_DESKTOP, cast(HMENU) null,
>                 hinstance, null);
>             SetWindowLongA(fhandle, 0, cast(LONG) cast(VOID*) this);
>             ShowWindow(fhandle, SW_SHOW);
> 
> And this in my WindowProc
> 
>     TWindow window = cast(TWindow) cast(void*)  GetWindowLongA(handle, 0);
>     if (window == null)  return DefWindowProcA(handle, msg, wparam, lparam);
> 
> but i keep getting an access violation on the if (window == null),
> 
> if i change it to
> 
>     if (window == null) beep(400,50)
> 
> i still get it, the AV that is, but if i just skip the check and call the
> DefWindoProcA it works fine.
> 
> I cant work out why, even if i have fecked up the casting or setting of the
> the windowLong var, testing what was returned against null shouldnt cause an
> AV should it?
> 
> Anycase, any ideas what I've done wrong?
> 
> cheers,
> 
> cw
> 
> 


This is definitely an F.A.Q.
Is there a D Programming FAQ anywhere?
'Why does "if (someobject == null)" keep crashing?' would definitely be 
there.
What else?

--bb


More information about the Digitalmars-d-learn mailing list