#include<wdm.h>
否则的话就看看_WIN32_WINNT在win7下面的定义,在代码上定义下。
进入wdk的环境cmd,有src文件夹吗,有的话,进入找一个目录build一下看看
没用过wdk7,还是使用ddk2600,wdk8.0好像没src目录了。
#include <windows.h>#include <dbt.h>
#include <stdio.h>
#include <math.h>
LRESULT CALLBACK WndProc(HWND h, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_DEVICECHANGE) {
if ((DWORD)wp == DBT_DEVICEARRIVAL) {
DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*) lp
if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) {
int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)))
printf("啊……%c盘插进来了\n", 'A' + l)
}
} else if ((DWORD)wp == DBT_DEVICEREMOVECOMPLETE) {
DEV_BROADCAST_VOLUME* p = (DEV_BROADCAST_VOLUME*) lp
if (p->dbcv_devicetype == DBT_DEVTYP_VOLUME) {
int l = (int)(log(double(p->dbcv_unitmask)) / log(double(2)))
printf("啊……%c盘被拔掉了\n", 'A' + l)
}
}
return TRUE
} else return DefWindowProc(h, msg, wp, lp)
}
int main() {
WNDCLASS wc
ZeroMemory(&wc, sizeof(wc))
wc.lpszClassName = TEXT("myusbmsg")
wc.lpfnWndProc = WndProc
RegisterClass(&wc)
HWND h = CreateWindow(TEXT("myusbmsg"), TEXT(""), 0, 0, 0, 0, 0,
0, 0, GetModuleHandle(0), 0)
MSG msg
while( GetMessage(&msg, 0, 0, 0) > 0 ) {
TranslateMessage(&msg)
DispatchMessage(&msg)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)