Analysis IP address (DDX)

Source: Internet
Author: User

 

 

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 .");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.