|
- #pragma comment(lib, "ws2_32.lib")
- WSADATA wsd;
- WSAStartup(MAKEWORD(2, 2), &wsd);
- DWORD size = MAX_PATH;
- char computerName[MAX_PATH] = { 0 };
- GetComputerNameA(computerName, &size);
- CString str;
- struct hostent* pHost = nullptr;
- pHost = gethostbyname(computerName);
- for (int i = 0; i < 4; i++)
- {
- CString addr;
- if (i > 0)
- {
- str += _T(".");
- }
- addr.Format(_T("%u"), (UINT)((UCHAR*)(pHost->h_addr_list[0]))[i]);
- str += addr;
- }
- SetWindowText(str);
- WSACleanup();
复制代码 |
|