C++ cast to D cast Part 2

BLS nanali at nospam-wanadoo.fr
Sat Sep 22 04:43:36 PDT 2007


Bill Baxter schrieb:
> BLS wrote:
>> Hi Bill.
>> Just something Regan and I allready have discussed ... but we are not 
>> sure about .
>>
>> C++
>> CWin* pActive= 
>> reinterpret_cast<CWin*>((HWND)::GetWindowLong(msg.hwnd,GWL_USERDATA));
>>
>> D
>> CWin pActive = cast(CWin) cast(HWND)GetWindowLong(msg.hwnd,GWL_USERDATA);
>>
>> where CWin is a class.
>> The problem here is that pActive in D is a reference.
>> Bjoern
>>
> 
> The problem I see is that cast for classes in D is like dynamic_cast<> 
> in C++.  It will return null if the typeinfo system doesn't think HWND 
> is a base class of CWin.
> 
> Maybe there's some way to disable that, like by casting to void* first? 
>   Or maybe it's smarter than I'm thinking.
> 
> --bb
You mean

CWin pActive = cast(CWin)cast(void*) 
cast(HWND)GetWindowLong(msg.hwnd,GWL_USERDATA);
???
Thanks
Bjoern


More information about the Digitalmars-d-learn mailing list