我一段代码在A里可以用,用的时候要加文件头,但是我把这段代码加到B中的时候,运行时出错,并且出的错和把A中的文件头注释后出的错差不多,请问谁知道这是怎么回事啊?
我加了头文件#include "Dbt.h",但是执行的时候老说
error C2065: 'DEV_BROADCAST_DEVICEINTERFACE' : undeclared identifier

解决方案 »

  1.   

    问题说得不明白,就是没有定义变量或者是结构'DEV_BROADCAST_DEVICEINTERFACE'
      

  2.   

    设置是一样的
    'DEV_BROADCAST_DEVICEINTERFACE' 
    这个是微软的基础类库里的啊,不用自己定义的, 只要加了#include "Dbt.h"就可以的
    我就是不知道为什么会出这样的错误
      

  3.   

    你的两个工程是不是在一起编译的???
    可能是这个问题:
     在以前的工程中定义了.h文件
    然后又定义了一遍因为.h文件中大多会有怎么一句
    #ifndefine ...._H_ 
    #define ..._H_ 
    可能是这样
      

  4.   

    那这个怎么解决啊?
    我是要把A的功能在B里实现,我就把A的主要代码都拷到B里了啊
      

  5.   

    typedef struct _DEV_BROADCAST_DEVICEINTERFACE {
      DWORD dbcc_size; 
      DWORD dbcc_devicetype; 
      DWORD dbcc_reserved; 
      GUID dbcc_classguid; 
      TCHAR dbcc_name[1]; 
    } DEV_BROADCAST_DEVICEINTERFACE *PDEV_BROADCAST_DEVICEINTERFACE;
    就是把这复制过去是吧?
    好象没用
      

  6.   

    typedef struct _DEV_BROADCAST_DEVICEINTERFACE {
      DWORD dbcc_size; 
      DWORD dbcc_devicetype; 
      DWORD dbcc_reserved; 
      GUID dbcc_classguid; 
      TCHAR dbcc_name[1]; 
    } DEV_BROADCAST_DEVICEINTERFACE, *PDEV_BROADCAST_DEVICEINTERFACE;
    中间有个逗号
      

  7.   

    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(187) : error C2065: 'DEV_BROADCAST_DEVICEINTERFACE' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(187) : error C2146: syntax error : missing ';' before identifier 'dbi'
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(187) : error C2065: 'dbi' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(189) : error C2228: left of '.dbcc_size' must have class/struct/union type
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(190) : error C2228: left of '.dbcc_devicetype' must have class/struct/union type
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(190) : error C2065: 'DBT_DEVTYP_DEVICEINTERFACE' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(191) : error C2228: left of '.dbcc_reserved' must have class/struct/union type
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(192) : error C2228: left of '.dbcc_classguid' must have class/struct/union type
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2065: 'HDEVNOTIFY' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2146: syntax error : missing ';' before identifier 'hDevNotify'
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2065: 'hDevNotify' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(196) : error C2065: 'RegisterDeviceNotification' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(199) : error C2065: 'DEVICE_NOTIFY_WINDOW_HANDLE' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(547) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(552) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(571) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(627) : warning C4018: '<' : signed/unsigned mismatch
    Generating Code...
    Error executing cl.exe.
    Creating browse info file...TimeClock.exe - 13 error(s), 4 warning(s)
    没加之前是上面的错误,加了之后
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(190) : error C2065: 'DBT_DEVTYP_DEVICEINTERFACE' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2065: 'HDEVNOTIFY' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2146: syntax error : missing ';' before identifier 'hDevNotify'
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(194) : error C2065: 'hDevNotify' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(196) : error C2065: 'RegisterDeviceNotification' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(199) : error C2065: 'DEVICE_NOTIFY_WINDOW_HANDLE' : undeclared identifier
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(547) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(552) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(571) : warning C4018: '<' : signed/unsigned mismatch
    C:\Documents and Settings\goodo\桌面\GoodoEastRiver3\TimeClockDlg.cpp(627) : warning C4018: '<' : signed/unsigned mismatch
    Generating Code...
    Error executing cl.exe.
    Creating browse info file...TimeClock.exe - 6 error(s), 4 warning(s)
    出错的地方代码为
    InitEditBox(); GUID hid_guid={0x4D1E55B2,0xF16F,0x11CF,0x88,0xCB,0x00,0x11,0x11,0x00,0x00,0x30};
    DEV_BROADCAST_DEVICEINTERFACE dbi;
    ZeroMemory(&dbi,sizeof(dbi));
    dbi.dbcc_size=sizeof(dbi);
    dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
    dbi.dbcc_reserved = 0;
    dbi.dbcc_classguid = hid_guid; HDEVNOTIFY hDevNotify;  hDevNotify = RegisterDeviceNotification(m_hWnd, 
            &dbi,
            DEVICE_NOTIFY_WINDOW_HANDLE
        );    if(!hDevNotify) 
        {
            int Err = GetLastError();
            printf( "RegisterDeviceNotification failed: %lx.\n", Err);
            return FALSE;
        }
      

  8.   

    自己已经找到错误的原因了
    在StdAfx.h添加   
      #define   WINVER   0x0500      
    具体参考http://blog.5d.cn/user18/sphinxzh/200612/336888.html