代码如下:
这段代码以前是没问题的,只不过我的系统被我重新安装了一次,可能我的设置被改变了,
但是我已经安装了winxp ddk,windows platform sdk,编译器的库路径也设了,应该没有问题才对,但现在不管怎样也编译不过,出错如下,哪位帮我编译一下看是否会跟我的问题一样,如何解决?
--------------------Configuration: DownMp3 - Win32 Release--------------------
Linking...
DownMp3Dlg.obj : error LNK2001: unresolved external symbol __imp__CM_Request_Device_EjectA@20
Release/DownMp3.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.DownMp3.exe - 2 error(s), 0 warning(s)
代码:
BOOL CDownMp3Dlg::RemoveUSBDeviceSafty()
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
//--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE) {
// 查询信息失败
//printf("ERROR - SetupDiGetClassDevs()");
return 1;
}
//--------------------------------------------------------------------------
// 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[MAX_PATH];
// LPWSTR vetoname=NULL;
ULONG ulStatus;
ULONG ulProblemNumber;
cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr ) {
//printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
//printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
//printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
} else {
//printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
//printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
// DN_DISABLEABLE or DN_REMOVABLE
if ((DN_DISABLEABLE & ulStatus ) != 0 ) {
//printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
} else {
continue;
}
if ((DN_REMOVABLE & ulStatus ) != 0 ) {
//printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
} else {
continue;
}
len = MAX_PATH;
cr = CM_Request_Device_Eject( DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0
);
if ( CR_SUCCESS == cr ) {
//printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
} else {
//printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
//printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
} }
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
//printf("error!");
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
//printf("finished!\n");
return 0;
}
这段代码以前是没问题的,只不过我的系统被我重新安装了一次,可能我的设置被改变了,
但是我已经安装了winxp ddk,windows platform sdk,编译器的库路径也设了,应该没有问题才对,但现在不管怎样也编译不过,出错如下,哪位帮我编译一下看是否会跟我的问题一样,如何解决?
--------------------Configuration: DownMp3 - Win32 Release--------------------
Linking...
DownMp3Dlg.obj : error LNK2001: unresolved external symbol __imp__CM_Request_Device_EjectA@20
Release/DownMp3.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.DownMp3.exe - 2 error(s), 0 warning(s)
代码:
BOOL CDownMp3Dlg::RemoveUSBDeviceSafty()
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i;
//--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE) {
// 查询信息失败
//printf("ERROR - SetupDiGetClassDevs()");
return 1;
}
//--------------------------------------------------------------------------
// 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[MAX_PATH];
// LPWSTR vetoname=NULL;
ULONG ulStatus;
ULONG ulProblemNumber;
cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr ) {
//printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
//printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
//printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
} else {
//printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
//printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
// DN_DISABLEABLE or DN_REMOVABLE
if ((DN_DISABLEABLE & ulStatus ) != 0 ) {
//printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
} else {
continue;
}
if ((DN_REMOVABLE & ulStatus ) != 0 ) {
//printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
} else {
continue;
}
len = MAX_PATH;
cr = CM_Request_Device_Eject( DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0
);
if ( CR_SUCCESS == cr ) {
//printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
} else {
//printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
//printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
} }
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
//printf("error!");
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo);
//printf("finished!\n");
return 0;
}
解决方案 »
- IOCP 入门级别问题。超级超级入门。。。走过路过不要错过
- WINDOW STYLE中的问题
- 全局钩子的问题
- 有关CFileDialog的问题,急
- 请教一个视频采集图象处理的问题,如何把显示出来的视频背景变做透明。谢谢!
- 求助:使用ado写excel文件出现问题
- XML DOM对象传递的问题
- 图象选块的拖曳、融合和合成提供源代码的网站,或书籍,先谢谢各位了
- 这个问题值多少分?请您给个数
- 这算不算Win64的巨大bug,你们难道都没有发现吗?
- FAQ上找的USB安全移除代码编译不过,哪位大侠编译通过的就帮一下我.全部代码都贴出来了,在线等.....分不够再加
- 为什么SQLBrowseConnect在带有unicode支持的dll中不能使用?
#include <stdio.h>
#include <windows.h>
#include <devguid.h>#define DWORD_PTR DWORD
#define ULONG_PTR DWORD
extern "C" {
#include "hidsdi.h"
}
// 需加入hid.lib#include <setupapi.h>
// 需加入setupapi.lib#include <regstr.h>
#include <winbase.h>#include <cfgmgr32.h>
// 需要加入cfgmgr32.lib#include <initguid.h>
//#include <usbiodef.h>
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICEint main(int argc, _TCHAR* argv[])
{
HDEVINFO hDevInfo;
SP_DEVINFO_DATA DeviceInfoData;
DWORD i; //--------------------------------------------------------------------------
// 获取设备信息
hDevInfo = SetupDiGetClassDevs((LPGUID)&GUID_CLASS_USB_DEVICE,
0, // Enumerator
0,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE );
if (hDevInfo == INVALID_HANDLE_VALUE)
{
// 查询信息失败
printf("ERROR - SetupDiGetClassDevs()");
return 1;
}
//-------------------------------------------------------------------------- // 枚举每个USB设备
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
for (i=0;SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData);i++)
{
LPTSTR buffer = NULL;
PVOID buffer2 = NULL;
DWORD buffersize = 0;
ULONG len;
CONFIGRET cr;
PNP_VETO_TYPE pnpvietotype;
CHAR vetoname[MAX_PATH];
ULONG ulStatus;
ULONG ulProblemNumber; cr = CM_Get_DevNode_Status( &ulStatus,
&ulProblemNumber,
DeviceInfoData.DevInst,
0);
if ( CR_SUCCESS == cr )
{
printf("OK - CM_Get_DevNode_Status()[%d]\n", cr);
printf("OK - CM_Get_DevNode_Status() sts [%x]\n", ulStatus);
printf("OK - CM_Get_DevNode_Status() pro [%x]\n", ulProblemNumber);
}
else
{
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", cr);
printf("ERROR - CM_Get_DevNode_Status()[%d]\n", GetLastError());
}
// DN_DISABLEABLE or DN_REMOVABLE
if ((DN_DISABLEABLE & ulStatus ) != 0 )
{
printf("HAS - DN_DISABLEABLE()[%x]\n", DN_DISABLEABLE & ulStatus);
}
else
{
continue;
}
if ((DN_REMOVABLE & ulStatus ) != 0 )
{
printf("HAS - DN_REMOVABLE()[%x]\n", DN_REMOVABLE & ulStatus);
}
else
{
continue;
} len = MAX_PATH;
// pnpvietotype = PNP_VetoDevice;
cr = CM_Request_Device_Eject(
DeviceInfoData.DevInst,
&pnpvietotype,
vetoname,
len,
0
);
if ( CR_SUCCESS == cr ) {
printf("OK - CM_Request_Device_Eject()[%d]\n", cr);
} else {
printf("ERROR - CM_Request_Device_Eject()[%d]\n", cr);
printf("ERROR - CM_Request_Device_Eject()[%d]\n", GetLastError());
} }
if ( GetLastError()!=NO_ERROR &&
GetLastError()!=ERROR_NO_MORE_ITEMS )
{
// Insert error handling here.
return 1;
}
// Cleanup
SetupDiDestroyDeviceInfoList(hDevInfo); return 0;
}
是我的环境哪里没设好呢?
我已经安装了winxp ddk ,sdk,并且cfgmgr32.dll在windows\system32中也有了.
到底是怎么了?
--------------------Configuration: removusb - Win32 Debug--------------------
Compiling...
removusb.cpp
Linking...
removusb.obj : error LNK2001: unresolved external symbol __imp__CM_Request_Device_EjectA@20
Debug/removusb.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.removusb.exe - 2 error(s), 0 warning(s)
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
#include <devguid.h>#define DWORD_PTR DWORD
#define ULONG_PTR DWORD
extern "C" {
#include "hidsdi.h"
}
// 需加入hid.lib
#pragma comment(lib,"hid.lib")
#include <setupapi.h>
// 需加入setupapi.lib
#pragma comment(lib,"setupapi.lib")
#include <regstr.h>
#include <winbase.h>#include <cfgmgr32.h>
// 需要加入cfgmgr32.lib
#pragma comment(lib,"cfgmgr32.lib")
#include <initguid.h>
//#include <usbiodef.h>
extern "C" {
#include "hidsdi.h"
}
这个文件需要用c的编码方式,需要定义一下
谢谢!
我试过了.也是一样.
如下:D:\WINDDK\2600\LIB\WXP\I386
谢谢!
但还是不行,我是这样的顺序.
extern "C" {
#include "hidsdi.h"
}
// 需加入hid.lib #include <cfgmgr32.h>
// 需要加入cfgmgr32.lib #include <setupapi.h>
// 需加入setupapi.lib #include <regstr.h>
#include <winbase.h>
#include <initguid.h>
//#include <usbiodef.h>
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE #pragma comment(lib,"cfgmgr32.lib")
#pragma comment(lib,"hid.lib")
#pragma comment(lib,"setupapi.lib")
非常感谢!
不知道您是如何知道的呢?
这是为什么?