阅读:5724回复:5
请教RegisterDeviceNotification编译问题!
我是在应用程序调用RegisterDeviceNotification登记监视设备的接口变化事件,但总是编译通不过,报错:
HDEVNOTIFY 没有定义、RegisterDeviceNotification没有定义 但我有include <dbt.h>了, 在MSDN上有这样一段代码: #include <windows.h> #include <dbt.h> HWND hWnd; BOOL DoRegisterDeviceInterface( GUID InterfaceClassGuid, HDEVNOTIFY *hDevNotify ) /* Routine Description: Registers for notification of changes in the device interfaces for the specified interface class GUID. Parameters: InterfaceClassGuid - The interface class GUID for the device interfaces. hDevNotify - Receives the device notification handle. On failure, this value is NULL. Return Value: If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. */ { DEV_BROADCAST_DEVICEINTERFACE NotificationFilter; char szMsg[80]; ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) ); NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE); NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; NotificationFilter.dbcc_classguid = InterfaceClassGuid; *hDevNotify = RegisterDeviceNotification( hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE ); if(!*hDevNotify) { wsprintf(szMsg, \"RegisterDeviceNotification failed: %d\\n\", GetLastError()); MessageBox(hWnd, szMsg, \"Registration\", MB_OK); return FALSE; } return TRUE; } 请问还要在工程里设置什么吗?谢谢! |
|
沙发#
发布于:2005-05-18 13:06
有人知道吗,快帮帮忙啊
|
|
板凳#
发布于:2005-05-18 15:04
1、在你的工程里加入DBT。H所在的目录
2、试着修改WINVER值>0x0500 3、HDEVNOTIFY并在不DBT。H中 |
|
|
地板#
发布于:2007-10-24 20:17
和楼主同样的问题
楼上的解答能否详细些? 有遇到过同样问题的人麻烦来解答以下。 尤其是关于WINVER的设置,在哪里修改? 谢谢 |
|
地下室#
发布于:2007-11-10 11:35
因为afx.h文件中已经定义了
#define WINVER 0x0400 但是HDEVNOTIFY定义要求 WINVER >= 0x0500 所以在stdAfx.h的#include之前中添加 #define WINVER 0x0500 |
|
5楼#
发布于:2007-11-12 08:35
引用第4楼happy-hg于2007-11-10 11:35发表的 : 非常感谢! |
|