Under MFC Unicode encoding, get the IP address described by CString and assign it to the CIPAddressCtrl control

Source: Internet
Author: User

1. Under Unicode encoding, the characters in CString are declared as wide words and should be obtained using the following method char*

CString Cstrip = strIp; // Convert CString to char* under Unicode int n = cstrip.getlength (); int len = WideCharToMultiByte (CP_ACP,0, Cstrip,cstrip.getlength (), NULL,0, null,null) ; Char New Char [len+1]; WideCharToMultiByte (CP_ACP,00;
View Code

2. Convert the IP address described by char* to Wdord

DWORD Dwip = inet_addr (p);
View Code

3. Assigning a DWORD value to a CIPAddressCtrl control

//get the Dwordip address from low to high, such as 127.0.0.1, will get 0x0100007f//need to be convertedm_host_ip. Setaddress ((Dwip&0xFF),//get 0~7 bit(Dwip &0xff00) >>8,//get 15~8 bit(Dwip &0xFF0000) >> -,//get 23~16 bit(Dwip &0xff000000) >> -);//get 31~24 bit
View Code

As above is all the code, if you have a more simple way, welcome advice ~

Under MFC Unicode encoding, get the IP address described by CString and assign it to the CIPAddressCtrl control

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.