1. 程式人生 > >獲取網路連線名稱“本地連線”的兩種方法

獲取網路連線名稱“本地連線”的兩種方法

#include "stdafx.h" #include #pragma comment(lib,"Iphlpapi.lib") #include #pragma comment(lib,"Rpcrt4.lib")//GUID #include //啟用、禁用網絡卡 #pragma comment(lib,"ole32.lib") #include int main(int argc, char* argv[]) { INetConnectionManager *pManager; INetConnection *pConnection; IEnumNetConnection *pEnum; ULONG           celtFetched; CoInitialize(NULL); CoCreateInstance(CLSID_ConnectionManager,   NULL,   CLSCTX_SERVER,   IID_INetConnectionManager,   (void**)&pManager); pManager->EnumConnections(NCME_DEFAULT,   &pEnum); pManager->Release();    while(   pEnum->Next(1,   &pConnection,   &celtFetched)   ==   S_OK   ) { NETCON_PROPERTIES*   properties; pConnection->GetProperties(&properties); DWORD dwNum = WideCharToMultiByte(CP_OEMCP,NULL,properties->pszwName,-1,NULL,0,NULL,FALSE); char *psText; psText = new char[dwNum]; if(!psText) { delete []psText; } WideCharToMultiByte (CP_OEMCP,NULL,properties->pszwName,-1,psText,dwNum,NULL,FALSE); printf(psText); printf("\r\n"); delete []psText; } return 0; }