Link to home
Create AccountLog in
System Programming

System Programming

--

Questions

--

Followers

Top Experts

Avatar of glenh
glenh

Still getting Assertion Fault on CIPAddressCtrl::SetAddress(DWORD ip);
I was too hasty when I closed out my old question so here goes another.

I was pointed to a better way to convert from a string IP to an unsigned long but my problem still exists.  Everytime I try to set the IP address via SetAddress() I get an assertion fault error.  This is absolutely driving me nuts lol.

here is how I am now converting to and from the CIPAddressCtrl.

This is when I try to set the IP address to the control.  The IP address is grabbed from a registry entry I have setup.  propertiesdialog in an instance of the Dialog the CIPAddressCtrl is on.
   const char *ip = registry.getserverip();

   serverip = inet_addr(ip);
   serverip = htonl(serverip);
   propertiesdialog.m_serverip.SetAddress(serverip);

This is where I blow up every time (the last line above).

Now the retreival from the CIPAddressCtrl works just fine and the funny thing is the value returned from GetAddress() is exactly the same as the value I am trying to push into SetAddress().  Here is my retreival function from the control.

   DWORD dwip;
   char *ip;
   IN_ADDR addr;
   
   m_serverip.GetAddress(dwip);
   addr.S_un.S_addr = ntohl(dwip);
   ip = inet_ntoa(addr);

Any further info would be great.  I have searched high and low on the internet but there is very little reference to this control.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of gurlygurly

What Assertion do you get ?

Avatar of glenhglenh

ASKER

I will check when I get home from work tonight but I honestly dont recall any particular message besides Assertion Fault Error.

Avatar of glenhglenh

ASKER

Actually I think I have pinpointed the problem but still dont quite understand the solution.  Bear with me as I am still self teaching myself MFC.

It seems I was referencing the CIPAddressCtrl outside the dialog class that declares it.  Doing so is what was causing the assertion fault.  I then overrided the OnInitDialog method in my CDialog class to initialize the CIPAddressCtrl to the value from the registry.  I am still getting the assertion fault error though.

I beleive the assertion fault error is because the control is not yet created as I can set the actual control if I wanted to in the function that runs when the OK button on the CDialog is pressed but nowhere else.  

How would I go about this?  I think I need to call the CIPAddressCtrl::Create method or something first but that will require a structure containing information I am not sure how to reference at this time.  

Raising the points for a good detailed explantion.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


If your ip address control is defined in the dialog template (meaning - you dragged an ip address control to your dialog in the dialog editor), than it is probably created when you get to your OnInitDialog.
If this is the case, make sure your implementation inside the OnInitDIalog is done AFTER the call to the base implemetation.

If you will send the specific line where the assertion occures, maybe it will give me a better idea about the problem.

Avatar of glenhglenh

ASKER

Here is a copy/paste of my header file and the OnInitDialog.  Actually i dont think its created in my onInitDialog though.  From what I read this is all the preprocessing before the creation as onInitDialog calls the DataExchange for loading the values on creation.  I am getting the assertion fault in the onInitDialog though.

Header File:
#if !defined(AFX_EQLP_SERVER_PROPERTIES_H__EB6ECF0B_2AB8_47B1_B667_33DF8200F804__INCLUDED_)
#define AFX_EQLP_SERVER_PROPERTIES_H__EB6ECF0B_2AB8_47B1_B667_33DF8200F804__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// EQLP_Server_Properties.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// EQLP_Server_Properties dialog

class EQLP_Server_Properties : public CDialog
{
// Construction
public:
     EQLP_Server_Properties(CWnd* pParent = NULL);   // standard constructor
   void SetIP(DWORD ip);
   BOOL OnInitDialog();

// Dialog Data
     //{{AFX_DATA(EQLP_Server_Properties)
     enum { IDD = IDD_DIALOG1 };
     CIPAddressCtrl     m_serverip;
     CEdit     m_svrportnumedit;
     CString     m_svrportnum;
     //}}AFX_DATA


// Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(EQLP_Server_Properties)
     protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
     //}}AFX_VIRTUAL

// Implementation
protected:

     // Generated message map functions
     //{{AFX_MSG(EQLP_Server_Properties)
     afx_msg void OnServerPropOk();
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_EQLP_SERVER_PROPERTIES_H__EB6ECF0B_2AB8_47B1_B667_33DF8200F804__INCLUDED_)




OnInitDialog member in cpp file:
BOOL EQLP_Server_Properties::OnInitDialog() {
   char *ip;
   DWORD dwIp;

   ip = EQLP_Registry::getserverip();
   dwIp = inet_addr(ip);
   m_serverip.SetAddress(ntohl(dwIp));//this is the line getting the assertion fault.

  return TRUE;
}



Exact Assertion Fault error:
Debug Assertion Failed!

Program: c:\EQLP_Client\Debug\EQLP_Client.exe
File: afxcmn.inl
Line: 301

Avatar of glenhglenh

ASKER

Actually, I just realized this morning what my problem was.  In my onInitDialog() fuction I need to first call the base class onInit which should create my control and allow access to the SetAddress function.  Testing this at work seemed to work and therefore should work on my home project.

BOOL CMyDialog::OnInitDialog()
{
     CDialog::OnInitDialog(); //This is the line of code I was missing
     
     // Add my code here
     
     return TRUE;  
}

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Glad to hear you found the problem.

ASKER CERTIFIED SOLUTION
Avatar of modulomodulo

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account
System Programming

System Programming

--

Questions

--

Followers

Top Experts

Kernel and system programming is the process of creating the software necessary for a computer or device to function and operate other programs. Some operating systems (such as Microsoft Windows) are proprietary, but others, such as the various Linux distributions, are open source.