7

这是我在 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 上无法运行:(

你能帮我找出错误吗?

非常感谢!

4

1 回答 1

6

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

于 2013-10-22T08:44:31.040 回答