用了sczyq(我又...........) 的紧用和启动网卡的程序,并且安装了DDK,包含文件都弄好了,可是报错是怎么回事。我是初级菜鸟,请大家指教
/*
还是帖出来吧, 我可是花了三天时间才搞定了.
*/
#include <SetupAPI.h>
#include <cfgmgr32.h> // cfgmgr32.h 在Microsoft Windows 2000 DDK 中.
// 要用 CM_Get_DevNode_Status(...) 来查询状态.
//---------------------------------------------------------------------------
typedef struct NetCardStruct
{
DWORD Id; // 网卡设备号
AnsiString Name; // 网卡名
bool Disabled; // 当前是否禁用
bool Changed; // 是否更改过
} TNetCardStruct;
typedef TNetCardStruct* PNetCardStruct;
//---------------------------------------------------------------------------
// EnumNetCards 枚举出网卡
//---------------------------------------------------------------------------
void __fastcall EnumNetCards(TList *NetDeviceList)
{
AnsiString DevValue;
PNetCardStruct NetCard;
DWORD Status, Problem;
LPTSTR Buffer = NULL;
DWORD BufSize = 0;
HDEVINFO hDevInfo = 0;
if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,0,DIGCF_PRESENT|DIGCF_ALLCLASSES)))
return;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
HKEY hKeyClass;
char DeviceName[200];
for (DWORD DeviceId=0;
SetupDiEnumDeviceInfo(hDevInfo,DeviceId,&DeviceInfoData); DeviceId++)
{
if (CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0) != CR_SUCCESS)
continue;
DevValue.SetLength(0);
if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_CLASS , &Buffer, (PULONG)&BufSize))
DevValue = Buffer;
if (DevValue == "Net")
{
DevValue.SetLength(0);
if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_ENUMERATOR_NAME , &Buffer, (PULONG)&BufSize))
DevValue = Buffer;
if (DevValue != "ROOT")
{
NetCard = new TNetCardStruct;
NetCard->Id = DeviceId;
NetCard->Name = "<Unknown Device>";
if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DRIVER , &Buffer, (PULONG)&BufSize))
if (GetRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC , &Buffer, (PULONG)&BufSize))
NetCard->Name = Buffer;
NetCard->Disabled = (Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem);
NetCard->Changed = false;
NetDeviceList->Add(NetCard);
}
}
}
}
//---------------------------------------------------------------------------
bool __fastcall GetRegistryProperty(HDEVINFO DeviceInfoSet,
PSP_DEVINFO_DATA DeviceInfoData, ULONG Property, PVOID Buffer, PULONG Length)
{
while (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
DeviceInfoData, Property, NULL, (BYTE *)*(TCHAR **)Buffer, *Length, Length))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
if (*(LPTSTR *)Buffer) LocalFree(*(LPTSTR *)Buffer);
*(LPTSTR *)Buffer = (PCHAR)LocalAlloc(LPTR,*Length);
}
else return false;
}
return (*(LPTSTR *)Buffer)[0];
}
//---------------------------------------------------------------------------
// NetCardStateChange 网卡的启用与禁用
// NetCardPoint 是 PNetCardStruct 的指针.
// Enabled true = 启用 false = 禁用
//---------------------------------------------------------------------------
bool __fastcall NetCardStateChange(void * NetCardPoint, bool Enabled)
{
PNetCardStruct NetCard = (PNetCardStruct)NetCardPoint;
DWORD DeviceId = NetCard->Id;
HDEVINFO hDevInfo = 0;
if (INVALID_HANDLE_VALUE == (hDevInfo =
SetupDiGetClassDevs(NULL,NULL,0,DIGCF_PRESENT|DIGCF_ALLCLASSES)))
return false;
SP_DEVINFO_DATA DeviceInfoData = {sizeof(SP_DEVINFO_DATA)};
DWORD Status, Problem;
if (!SetupDiEnumDeviceInfo(hDevInfo,DeviceId,&DeviceInfoData))
return false;
if (CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0) != CR_SUCCESS)
return false;
SP_PROPCHANGE_PARAMS PropChangeParams = {sizeof(SP_CLASSINSTALL_HEADER)};
PropChangeParams.ClassInstallHeader.InstallFunction = DIF_PROPERTYCHANGE;
PropChangeParams.Scope = DICS_FLAG_GLOBAL;
if (Enabled)
{
if (!((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem)))
{
NetCard->Disabled = false;
return false;
}
PropChangeParams.StateChange = DICS_ENABLE;
}
else
{
if ((Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem))
{
NetCard->Disabled = true;
return false;
}
if (!((Status & DN_DISABLEABLE) && (CM_PROB_HARDWARE_DISABLED != Problem)))
return false;
PropChangeParams.StateChange = DICS_DISABLE;
}
if (!SetupDiSetClassInstallParams(hDevInfo, &DeviceInfoData,
(SP_CLASSINSTALL_HEADER *)&PropChangeParams, sizeof(PropChangeParams)))
return false;
if (!SetupDiCallClassInstaller(DIF_PROPERTYCHANGE, hDevInfo, &DeviceInfoData))
return false;
if (CM_Get_DevNode_Status(&Status, &Problem,
DeviceInfoData.DevInst,0) == CR_SUCCESS)
NetCard->Disabled = (Status & DN_HAS_PROBLEM) && (CM_PROB_DISABLED == Problem);
return true;
}
报错全在cfgmgr32.h文件中
[C++ Error] cfgmgr32.h(2416): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
[C++ Error] cfgmgr32.h(2427): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
[C++ Error] cfgmgr32.h(2438): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
[C++ Error] cfgmgr32.h(2450): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
[C++ Error] cfgmgr32.h(2473): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
[C++ Error] cfgmgr32.h(2484): E2015 Ambiguity between 'PHKEY' and 'Windows::PHKEY'
请指教,谢谢。。。