Pointers, casting, SetGetWindowLong problem...

Chris Warwick sp at m.me.not
Fri Mar 9 17:19:12 PST 2007


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:essrhi$vgr$1 at digitalmars.com...
> 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.

It would certainly help if this was mentioned in the docs section on 
classes.

cheers,

cw 




More information about the Digitalmars-d-learn mailing list