#include <stdio.h>
#include <string.h>
unsigned char sysdir[256];
unsigned char drivcedir[256];
int RegHandelDev(char * exename)
{
    //修改注册表启动一个NTHANDLE驱动程序
    char subkey[200];
    int buflen;
    HKEY hkResult;
    char Data[4];
    DWORD isok;
    buflen = sprintf(subkey,"System\\CurrentControlSet\\Services\\%s",exename);
    subkey[buflen]=0;
    isok = RegCreateKey(HKEY_LOCAL_MACHINE,subkey,&hkResult);
    if(isok!=ERROR_SUCCESS)
        return FALSE;
    Data[0]=3;
    Data[1]=0;
    Data[2]=0;
    Data[3]=0;    
    isok=RegSetValueEx(hkResult,"Start",0,4,(const unsigned char *)Data,4);
    Data[0]=1;
    isok=RegSetValueEx(hkResult,"Type",0,4,(const unsigned char *)Data,4);
    isok=RegSetValueEx(hkResult,"ErrorControl",0,4,(const unsigned char *)Data,4);    
    GetSystemDirectory(sysdir,256);
    buflen = sprintf(drivcedir,"%s\\Drivers\\FxFiltHook.sys",sysdir);
    buflen = sprintf(subkey,"\\??\\%s",drivcedir);
    subkey[buflen]=0;
    isok=RegSetValueEx(hkResult,"ImagePath",0,1,(const unsigned char *)subkey,buflen);
    RegCloseKey(hkResult);    
    buflen = sprintf(subkey,"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%s",exename);
    subkey[buflen]=0;
    return TRUE;
}
int main(int argc,char *argv[])
{
    //注册驱动程序
    if(RegHandelDev("Fxfilthook")==FALSE)
        return FALSE;
     return TRUE;
}
、、、、、、、、、、、、、、、、
、、、、、、、、、、、、、、、、、、、、
上面一段程序编译错误15,而都是一些简单的数据类型没定义的错误我实在是想不出还需要什么头文件
大家可以直接把上面的那段程序复制上去试试
错误提示
error C2065: 'HKEY' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hkResult'
error C2065: 'hkResult' : undeclared identifier
error C2065: 'DWORD' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'isok'
error C2065: 'isok' : undeclared identifier
error C2065: 'RegCreateKey' : undeclared identifier
error C2065: 'HKEY_LOCAL_MACHINE' : undeclared identifier
error C2065: 'ERROR_SUCCESS' : undeclared identifier
error C2065: 'FALSE' : undeclared identifier
error C2065: 'RegSetValueEx' : undeclared identifier
error C2065: 'GetSystemDirectory' : undeclared identifier
error C2664: 'sprintf' : cannot convert parameter 1 from 'unsigned char [256]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2065: 'RegCloseKey' : undeclared identifier
error C2065: 'TRUE' : undeclared identifier
Error executing cl.exe.Fxfilthook.exe - 15 error(s), 0 warning(s)

解决方案 »

  1.   

    where u defined "HKEY"? check ur code, miss some files
      

  2.   

    你光加入#include <stdio.h>和#include <string.h>有什么用?你是在写Windows应用程序啊!
      

  3.   

    可是我查MSDN sprintf需要<stdio.h>所以我才加的,
    无论是加#include <stdio.h>和#include <string.h>还是不加都是一样的错误,我是写DOS程序,可是只有加WINDOWS.H错误会少的,可是上面的错误只的都是最基本的数据类型没定义啊!
      

  4.   

    HKEY是在winreg.h中声明的,你不包含头文件肯定会出现类型没定义的错误呀,一定要加上windows.h
      

  5.   

    同意,只要你使用了WinAPI,你就必须在头部包含windows.h。
      

  6.   

    #include <windows.h>
    你用到了API函数RegCreateKey,
    还有win32数据类型HKEY
      

  7.   

    真的是不利有出现下面问题
    error C2664: 'GetSystemDirectoryA' : cannot convert parameter 1 from 'unsigned char [256]' to 'char *'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    error C2664: 'sprintf' : cannot convert parameter 1 from 'unsigned char [256]' to 'char *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.Fxfilthook.exe - 2 error(s), 0 warning(s)、、、、、、、、、、、、、、、、、、、、、、、、、、、
    只得是这两句
    buflen = sprintf(drivcedir,"%s\\Drivers\\FxFiltHook.sys",sysdir);
    buflen = sprintf(subkey,"\\??\\%s",drivcedir);
    我刚看了MSDN我个人认为没错啊!
    急。。这个问题摸了我一天了
      

  8.   

    类型转换错误,你强制转换一下就ok了GetSystemDirectory((LPSTR)sysdir,256);   
    buflen = sprintf((char*)drivcedir,"%s\\Drivers\\FxFiltHook.sys",sysdir);