gpt4 book ai didi

c++ - 通过 WinAPI 禁用/启用网络接口(interface)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:35:19 26 4
gpt4 key购买 nike

这是我在 Windows 上禁用/启用网络适配器的尝试:

void EnableNetDevice(bool aState, int index)
{
HDEVINFO NetPnPHandle;
SP_PROPCHANGE_PARAMS PCHP;
SP_DEVINFO_DATA DeviceData;
NetPnPHandle = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, 0, 0, DIGCF_PRESENT);

if (NetPnPHandle == INVALID_HANDLE_VALUE)
{
return;
}

DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
SetupDiEnumDeviceInfo(NetPnPHandle, index, &DeviceData);
PCHP.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);

if (SetupDiSetClassInstallParams(NetPnPHandle,&DeviceData,&PCHP.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS)))
{
PCHP.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
PCHP.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PCHP.HwProfile = 0;
PCHP.Scope = DICS_FLAG_CONFIGSPECIFIC;
if (aState) PCHP.StateChange = DICS_ENABLE;
else PCHP.StateChange = DICS_DISABLE;
SetupDiSetClassInstallParams(NetPnPHandle,&DeviceData,&PCHP.ClassInstallHeader,sizeof(SP_PROPCHANGE_PARAMS));
SetupDiCallClassInstaller(DIF_PROPERTYCHANGE,NetPnPHandle,&DeviceData);
}

DeviceData.cbSize = sizeof(SP_DEVINFO_DATA);
SetupDiDestroyDeviceInfoList(NetPnPHandle);
}

问题是它在 Windows XP 上完美运行在 Win 7 上不起作用:(

你能帮我找到错误吗?

非常感谢!

最佳答案

这只是在 x64 操作系统上从 64 位进程调用函数的要求。参见 http://msdn.microsoft.com/en-us/library/windows/hardware/ff541255(v=vs.85).aspx

关于c++ - 通过 WinAPI 禁用/启用网络接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17331449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com