Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Visual Studio 2012. I have this field on a dialog that is not modal.

I have declared this member:

C++
CIPAddressCtrl m_ctlIpAddress;

I have this code to get the DWORD address for the IP address from a camera via dll.
C++
void CCamNetworkDlg::SetIpAddress(void){

    unsigned long dwAddress = 0;

    ForzaDllForzaGetParam( 0 ,P_IPv4 ,(char*)&dwAddress ,sizeof(long) );
    
    m_ctlIpAddress.SetAddress(dwAddress);  
}

When I get to the SetAddress I get an assretion error. I have checked and I am getting the correct address from the dll.

When I use this code I can break it down into it components for each field and I see the correct values.
C++
unsigned long dwAddress = -1062730708;

    nField0 = (dwAddress & (0xff << 24)) >> 24;
    nField1 = (dwAddress & (0xff << 16)) >> 16;
    nField2 = (dwAddress & (0xff << 8)) >> 8;
    nField3 = dwAddress & 0xff;


This is the assertion that is thrown.
{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, IPM_SETADDRESS, 0, (LPARAM) dwAddress); }

Any ideas on what I am doing wrong?
Posted
Updated 11-Apr-13 5:56am
v3

This is because m_hWnd is required to be a valid window handle registers in Windows at the moment of the call. As you never show other calls where m_hWnd is involved, it's hard to say what exactly missing, but the idea is simple: a window's should be created and assigned to this member prior to calling the function with this assertion. The assertion simply tries to protect you from this inconsistency and suggest you the fix.

At the level of raw Windows API, the handle is created by one of these calls:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680%28v=vs.85%29.aspx[^].

It does not mean that you have to call one of these functions directly. The very usual mistake is: the window handle is created somewhere, but you call the method with assertion too early. You would need to call it later. For example, you could call it when a window is already shown. This would be even too late, but 100% sure that the handle is already created.

—SA
 
Share this answer
 
Comments
Member 9892295 11-Apr-13 13:04pm    
Here is where I am creating this window. I am using a dialog with two controls on it. One of which is the IP Address that I am trying to update.

BOOL CCamDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// Creation and initialization of TabCtrl.
if(m_TabCtrl.Create(this, WS_CHILD | WS_VISIBLE ,
CRect(0,0,275,300), 100 )==false) return -1;
m_TabCtrl.SetBehavior(TAB_BEHAVIOR_SCROLL);
m_TabCtrl.EqualTabsSize(true);

BOOL bCreate1 = m_Dlg1.Create( IDD_CAMERA_CTL ,&m_TabCtrl );
BOOL bCreate2 = m_Dlg2.Create( IDD_CAM_SETTINGS ,&m_TabCtrl );
BOOL bCreate3 = m_Dlg3.Create( IDD_CAM_NETWORK ,&m_TabCtrl );
m_Dlg1.SetDlgCtrlID( 2000 );
m_Dlg2.SetDlgCtrlID( 2001 );
m_Dlg3.SetDlgCtrlID( 2002 );

if( !bCreate1 || !bCreate2 ){
return -1;
}

// Attaching of child windows to the TabCtrl.
if(m_TabCtrl.Add(m_Dlg1,_T("Camera"),0)==NULL ||
m_TabCtrl.Add(m_Dlg2,_T("Settings"),1)==NULL ||
m_TabCtrl.Add(m_Dlg3,_T("Network"),2)==NULL
)
return -1;

_beginthread( &CCamCtlDlg::LivePaintThx ,0 ,&m_Dlg1 );


// Load state from registry and update.
m_TabCtrl.LoadState(AfxGetApp(),_T("TabCtrl"),_T("State"));
m_TabCtrl.Update();

return TRUE;
}

The m_Dlg3 is the CCamNetwork dialog which has the IP control on it. When the software starts I can see the window and the tab with that dialog on it so I know that it is drawn. When I choose the network card that the camera is on I get the assertion. Does this help with trying to understand where I am having the problem?
Sergey Alexandrovich Kryukov 11-Apr-13 15:18pm    
OK, and where is the window handle?..
—SA
I have the same question,do you have a solution?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900