当前位置:网站首页>MFC obtains local IP (used more in network communication)
MFC obtains local IP (used more in network communication)
2022-07-01 17:47:00 【ToneSole】
CString CUDPDlg::GetIP() // Access to the local IP
{
WORD wVersionRequested;
WSADATA wsaData;
char name[255]; // Local hostname array variable
CString m_ip; // IP Address string variable
PHOSTENT hostinfo; // hostent Structure pointer
wVersionRequested = MAKEWORD(2, 0); // Connecting applications to winsock Dll
if (WSAStartup(wVersionRequested, &wsaData) == 0)
{
if (gethostname(name, sizeof(name)) == 0) // Get the local host name
{
if ((hostinfo = gethostbyname(name)) != NULL) // Get host information
{
m_ip = inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list); // Convert to get IP Address
}
else m_ip = "IP Detection failed ";
}
WSACleanup(); // suspend winsock DLL Use
}
return m_ip; // return IP Address string
}
Call the following
CString localIP;
localIP = GetIP(); // Get this machine IP
SetDlgItemText(IDC_IP1, localIP); // Get local IP Display to the interface
边栏推荐
- Openlayers 自定义气泡框以及定位到气泡框
- Is it safe to open an ETF account online? What are the steps?
- 存在安全隐患 起亚召回部分K3新能源
- [beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)
- 期货先锋这个软件正规吗安全吗?选择哪家期货公司更安全?
- Shenyu gateway development: enable and run locally
- 中国PBAT树脂市场预测及战略研究报告(2022版)
- PETRv2:一个多摄像头图像3D感知的统一框架
- 整形数组合并【JS】
- Good looking UI mall source code has been scanned, no back door, no encryption
猜你喜欢

Work and leisure suggestions of old programmers

Yyds dry inventory MySQL RC transaction isolation level implementation

There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds

SQL injection vulnerability (MySQL and MSSQL features)

How to use JMeter function and mockjs function in metersphere interface test

整形数组合并【JS】

The difference and relationship between iteratible objects, iterators and generators

Good looking UI mall source code has been scanned, no back door, no encryption

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

Source code of new campus errand / campus task platform on mutual station
随机推荐
Smart factory digital management system software platform
How to write good code - Defensive Programming Guide
Source code of new campus errand / campus task platform on mutual station
Gold, silver and four want to change jobs, so we should seize the time to make up
transform. Forward and vector3 Differences in the use of forward
Countdownlatch blocking wait for multithreading concurrency
[C supplement] [string] display the schedule of a month by date
换掉UUID,NanoID更快更安全!
GameFramework食用指南
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
The new server is packaged with the source code of H5 mall with an operation level value of several thousand
Kernel stray cat stray dog pet adoption platform H5 source code
[PHP foundation] realize the connection between PHP and SQL database
官宣!香港科技大学(广州)获批!
Cassette helicopter and alternating electric field magnetic manometer DPC
线上开通ETF基金账户安全吗?有哪些步骤?
两数之和c语言实现[通俗易懂]
(28) Shape matching based on contour features
Function, condition, regular expression
麦趣尔:媒体报道所涉两批次产品已下架封存,受理消费者诉求