当前位置:网站首页>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
边栏推荐
- MySQL restores or rolls back data through binlog
- js获取本机ip地址
- Customize the non slidable viewpage and how to use it
- Speculation on the way to realize the smooth drag preview of video editing software
- Golang timer
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- Lottery applet, mother no longer have to worry about who does the dishes (assign tasks), so easy
- goroutine
- Gossip: on greed
- Web Security
猜你喜欢

Oracle配置st_geometry

开关电源设计分享及电源设计技巧图解

精简CUDA教程——CUDA Driver API

Network protocol: SCTP flow control transmission protocol

Class loading mechanism
![[report] Microsoft: application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[report] Microsoft: application of deep learning methods in speech enhancement

Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。

JVM的类加载过程

Zero cost, zero foundation, build profitable film and television applet
![[报告] Microsoft :Application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[报告] Microsoft :Application of deep learning methods in speech enhancement
随机推荐
開關電源設計分享及電源設計技巧圖解
Gossip: on greed
Redis core technology and practice 1 - start with building a simple key value database simplekv
Class loading process of JVM
深度学习环境搭建步骤—gpu
Redis optimization series (III) solve common problems after master-slave configuration
How to select the third-party package of golang
Application of DCT transform
Common processing of point cloud dataset
Steps to build a deep learning environment GPU
5 minutes to achieve wechat cloud applet payment function (including source code)
RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
Decompile and get the source code of any wechat applet - just read this (latest)
Network protocol: SCTP flow control transmission protocol
Modify the font size of hint in editext
PostgreSQL
Regular expressions for judging positive integers
A brief explanation of golang's keyword "competence"
[transfer] summary of new features of js-es6 (one picture)
MySQL syntax collation (3)