If you writeFor Internet applications, You need to verify the IP address entered by the user and confirm that it is correct.
First, we need to add the following function declaration in the header file of the dialog box:
# Include <winsock. h>
Void WINAPI DDX_IPAddress (CDataExchange * pDX, int nIDC, UINT & value );
To achieve data exchange, you need to go to your dialog boxCall the DDX_IPAddress function in the DoDataExchange function.
Now, add the following code to the implementation file of the dialog box. Do not forget to include ws2_32.lib in the project settings.
// DDX routine fo IP address translation
Void WINAPI DDX_IPAddress (CDataExchange * pDX, int nIDC, UINT & value)
{
// From dialog to class?
If (pDX-> m_bSaveAndValidate)
{
CString Val;
BOOL bValid = true;
PDX-> m_pDlgWnd-> GetDlgItem (nIDC)-> GetWindowText (Val );
For (int I = 0; I <Val. GetLength (); I ++)
{
// Lets check if all entered char in entered
// IP address are digits
If (Val [I] = .)
Continue;
If (isdigit (Val [I]) = 0)
{
BValid = false;
Break;
}
}
If (bValid)
{
Value = inet_addr (Val );
If (value = INADDR_NONE)
{
PDX-> m_pDlgWnd-> MessageBox ("The entered IP address is invalid .");