概述:通过 COM 对象操作网卡
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <NetCon.h> void ChangeNetState() { CoInitialize(NULL); INetConnectionManager* pNetManager; INetConnection* pNetConnection; IEnumNetConnection* pEnum;
if (S_OK != CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_SERVER, IID_INetConnectionManager, (void**)&pNetManager)) { return ; }
pNetManager->EnumConnections(NCME_DEFAULT, &pEnum); pNetManager->Release(); if (NULL == pEnum) { return ; }
ULONG celtFetched; while (pEnum->Next(1, &pNetConnection, &celtFetched) == S_OK) { NETCON_PROPERTIES* properties; pNetConnection->GetProperties(&properties);
} CoUninitialize(); return ; }
|
NETCON_PROPERTIES
结构体使用的变量为宽字符,在打印时需要在程序入口调用以下函数才能正确输出。
1
| setlocale(LC_CTYPE, "chs");
|