C++ cast to D cast again :)

BLS nanali at nospam-wanadoo.fr
Sun Sep 30 03:00:45 PDT 2007


Hi and sorry about picking on your nerves again  :(
// C++
class CWin
{
//
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uID, WPARAM wParam, 
LPARAM lParam)
{
   CWin* pWnd=NULL;  // init pWnd
}

// later ...
CWin* pChild=reinterpret_cast<CWin*>((HWND)
::GetWindowLong(pWnd->GetDlgItem( ((( LPDRAWITEMSTRUCT )lParam)->CtlID) 
),GWL_USERDATA) );


}

//our D class
class CWin
{
static LRESULT WndProc(HWND hWnd, UINT uID, WPARAM wParam, LPARAM lParam)
{
   CWin pWnd=null;  // init pWnd as    ---reference !
}
/* instead of :
CWin* pChild=reinterpret_cast<CWin*>
we use
CWin pChild = cast(CWin) cast(void*)

But I am not sure how to translate :
((HWND)
::GetWindowLong(pWnd->GetDlgItem( ((( LPDRAWITEMSTRUCT )lParam)->CtlID) 
),GWL_USERDATA) );
*/

// Later we have
if (HIWORD(pWnd))

/*Since we are working with a ref. instead of a pointer this will not work.
I guess I can use :
*/

if (HIWORD(cast(void*)pWnd))
// can you confirm
}

GetWindowLong() is a Windows Api func., sure you know it.
So what the correct translation ?
Bjoern
Beside, I still wonder : Having a class A, Is A* pA a legal construct in D.
What is pA from a technical view; a pointer to a reference ?


More information about the Digitalmars-d-learn mailing list