有一点疑问:编译生成的是x64的exe,但是引用的是system32目录下的dll,setupapi.dll
如果是32位的exe,但是引用的是SysWOW64目录下的dll。
有没有大神帮忙解决下。
DWORD NewState;
DWORD flag;
//#define DICS_ENABLE 0x00000001
//#define DICS_DISABLE 0x00000002
//#define DICS_START 0x00000004
//#define DICS_STOP 0x00000005
if (bStatus == TRUE) {
NewState = DICS_ENABLE;
flag = SPDRP_HARDWAREID;
} else {
NewState = DICS_DISABLE;
flag = SPDRP_DEVICEDESC;
}
printf("EnableNetInterface status[%d]: %s\n", bStatus, deviceName);
//调用ddk函数,来禁用网卡
DWORD i ;
BOOL Found=FALSE ;
HDEVINFO hDevInfo ;
SP_DEVINFO_DATA spDevInfoData ;
hDevInfo=SetupDiGetClassDevs(NULL,NULL,NULL,DIGCF_ALLCLASSES );
if(hDevInfo==INVALID_HANDLE_VALUE)
{
printf("access system hardware failed!");
return FALSE ;
}
//枚举硬件,获得需要的接口
spDevInfoData.cbSize=sizeof(SP_DEVINFO_DATA);
for(i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &spDevInfoData); i++) {
DWORD DataT ;
LPTSTR p;
DWORD buffersize = 1024 ;
TCHAR buffer[1024];
//获得硬件的属性值
while(!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&spDevInfoData,
flag, /* flag为这些类型: SPDRP_DEVTYPE, SPDRP_HARDWAREID, SPDRP_FRIENDLYNAME, SPDRP_DEVICEDESC */
&DataT,
(PBYTE)&buffer,
1024,
&buffersize)) {
break;
}
if(GetLastError() == ERROR_INVALID_DATA)
continue;
//比较,找到和网卡ID相同的项
int count = 0;
for(p = buffer; *p && (p < &buffer[buffersize]); p += lstrlen(p) + sizeof(TCHAR)) {
printf("[%d]%s", count, buffer);
size_t len = _tcslen(deviceName);
if (_tcsnicmp(deviceName,buffer, len)==0) {
printf("Device[%s] Finded\n", deviceName);
Found=TRUE ;
break;
}
}
//如果相等
if (Found) {
//NewState = DICS_DISABLE;
SP_PROPCHANGE_PARAMS spPropChangeParams ;
spPropChangeParams.ClassInstallHeader.cbSize = sizeof(SP_CLASSINSTALL_HEADER);
spPropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE ;
spPropChangeParams.Scope = DICS_FLAG_CONFIGSPECIFIC; //DICS_FLAG_GLOBAL, DICS_FLAG_CONFIGSPECIFIC;
spPropChangeParams.StateChange = NewState;
spPropChangeParams.HwProfile = 0;
//禁用:DICS_DISABLE,DICS_ENABLE启用
if (!SetupDiSetClassInstallParams(hDevInfo, &spDevInfoData, (SP_CLASSINSTALL_HEADER *)&spPropChangeParams, sizeof(spPropChangeParams))) {
DWORD errorcode = GetLastError();
SetupDiDestroyDeviceInfoList(hDevInfo);
printf("SetupDiSetClassInstallParams is fail, rv = %x!", errorcode);
return FALSE;
}
if(!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &spDevInfoData))
{
DWORD errorcode = GetLastError();
SetupDiDestroyDeviceInfoList(hDevInfo);
printf("SetupDiCallClassInstaller is fail, rv = %x!", errorcode);
return FALSE;
}
break;
}
}
//退出时,清理工作环境
SetupDiDestroyDeviceInfoList(hDevInfo);
return TRUE ;
1 个解决方案
#1
顶一个,我也遇到这个问题了。
哪位大神给解答一下啊。
哪位大神给解答一下啊。
#1
顶一个,我也遇到这个问题了。
哪位大神给解答一下啊。
哪位大神给解答一下啊。