工控编程吧
标题: 上位机MFC如何获得本地计算机的网络协议信息 [打印本页]
作者: qq263946146 时间: 2019-8-8 10:39
标题: 上位机MFC如何获得本地计算机的网络协议信息
- void CGkbc8Dlg::OnButton2()
- {
- //初始化WinSock
- WSADATA WSAData;
- if (WSAStartup(MAKEWORD(2,0), &WSAData)!= 0)
- {
- return;
- }
- int nResult = 0;
- //获得需要的缓冲区大小
- DWORD nLength = 0;
- nResult = WSAEnumProtocols(NULL, NULL, &nLength);
- if (nResult != SOCKET_ERROR)
- {
- return;
- }
- if (WSAGetLastError() != WSAENOBUFS)
- {
- return;
- }
- WSAPROTOCOL_INFO* pProtocolInfo = (WSAPROTOCOL_INFO*)new BYTE[nLength];
- //获得本地计算机协议信息
- nResult = WSAEnumProtocols(NULL, pProtocolInfo, &nLength);
- if (nResult == SOCKET_ERROR)
- {
- delete[] pProtocolInfo;
- return;
- }
- for (int n = 0; n < nResult; n++)
- {
- m_ctrlList.AddString(pProtocolInfo[n].szProtocol);
- }
- delete[] pProtocolInfo;
- //清理WinSock
- WSACleanup();
- }
复制代码 调用上面代码就可以显示出协议相关信息。m_ctrlList为我们添加的控件变量CListBox m_ctrlList;
(, 下载次数: 1)