当前位置:网站首页>MFC获取本机IP(网络通讯时用得多)
MFC获取本机IP(网络通讯时用得多)
2022-04-23 19:24:00 【ToneChip】
CString CUDPDlg::GetIP() //获取本地IP
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255]; // 本地主机名字符数组变量
CString m_ip; // IP地址字符串变量
PHOSTENT hostinfo; // hostent结构指针
wVersionRequested = MAKEWORD(2, 0); //连接应用程序与winsock Dll
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == 0) //得到本地主机名
{
if ((hostinfo = gethostbyname(name)) != NULL) //得到主机信息
{
m_ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); //转换得到IP地址
}
else m_ip = "IP检测失败";
}
WSACleanup(); // 中止winsock DLL的使用
}
return m_ip; //返回IP地址字符串
}
调用如下
CString localIP;
localIP = GetIP(); //得到本机IP
SetDlgItemText(IDC_IP1, localIP); //获取到的本机IP显示到界面
版权声明
本文为[ToneChip]所创,转载请带上原文链接,感谢
https://tonechip.blog.csdn.net/article/details/122943159
边栏推荐
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
- No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
- The usage of slice and the difference between slice and array
- SSDB foundation 1
- How to use go code to compile Pb generated by proto file with protoc Compiler Go file
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- [report] Microsoft: application of deep learning methods in speech enhancement
- Matlab 2019 installation of deep learning toolbox model for googlenet network
- How to uninstall easyton
- The platinum library cannot search the debug process records of some projection devices
猜你喜欢

RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
![[报告] Microsoft :Application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[报告] Microsoft :Application of deep learning methods in speech enhancement

First experience of using fluent canvas

Openharmony open source developer growth plan, looking for new open source forces that change the world!

MySQL syntax collation
![[报告] Microsoft :Application of deep learning methods in speech enhancement](/img/c1/7bffbcecababf8dabf86bd34ab1809.png)
[报告] Microsoft :Application of deep learning methods in speech enhancement

Wechat applet part of the mobile phone Preview PDF did not respond

No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)

Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
![[report] Microsoft: application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[report] Microsoft: application of deep learning methods in speech enhancement
随机推荐
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
ArcMap连接 arcgis server
JVM的类加载过程
What is a message queue
SQL常用的命令
Garbage collector and memory allocation strategy
The difference between ordinary inner class and static inner class
Common processing of point cloud dataset
Core concepts of rest
FTP, SSH Remote Access and control
How to select the third-party package of golang
Convert string to JSON
openlayers 5.0 热力图
js上传文件时控制文件类型和大小
浅谈c语言指针的强制转换
Pit encountered using camera x_ When onpause, the camera is not released, resulting in a black screen when it comes back
Wechat video extraction and receiving file path
Main differences between go and PHP
The flyer realizes page Jump through routing routes
Strange passion