新写了硬件设备驱动,有现成的INF和SYS文件,可以用控制面板系统设备添加并正常使用。但用网络上给出的编程动态添加总是不能正确加载。怎么办好?急求啊。答案正确给满100后继续开一加分帖给满另外400分。

解决方案 »

  1.   

    http://www.codeproject.com/system/tdriver.asp
      

  2.   

    char *p;
      ::GetFullPathName("CPNDriver.sys",256,szDriverPath,&p);
      if(notifying==false)
      {
        hSCM = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
        if(hSCM==NULL)
        {
          ShowMessage("打开服务控制管理器失败.");
          notifying = false;
          Button1->Enabled = true;
          Button2->Enabled = false;
          Button3->Enabled = true;
          return;
        }
        hService = CreateService(hSCM,szLinkName,szLinkName,SERVICE_ALL_ACCESS,
                                 SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,
                                 SERVICE_ERROR_NORMAL,szDriverPath,
                                 NULL,0,NULL,NULL,NULL);
        if(hService==NULL)
        {
          int nError = GetLastError();
          if(nError==ERROR_SERVICE_EXISTS || nError==ERROR_SERVICE_MARKED_FOR_DELETE)
          {
            hService = OpenService(hSCM,szLinkName,SERVICE_ALL_ACCESS);
          }
        }
        if(hService==NULL)
        {
          ShowMessage("创建服务出错.");
          CloseServiceHandle(hSCM);
          notifying = false;
          Button1->Enabled = true;
          Button2->Enabled = false;
          Button3->Enabled = true;
          return;
        }
        if(!StartService(hService,0,NULL))
        {
          int nError = GetLastError();
          if(nError != ERROR_SERVICE_ALREADY_RUNNING)
          {
            ShowMessage("启动服务出错.");
            DeleteService(hService);
            CloseServiceHandle(hService);
            CloseServiceHandle(hSCM);
            notifying = false;
            Button1->Enabled = true;
            Button2->Enabled = false;
            Button3->Enabled = true;
            return;
          }
        }
        char szDriverFile[256] = "";
        wsprintf(szDriverFile,"\\\\.\\%s",szLinkName);
        hDriver = CreateFile(szDriverFile,GENERIC_READ|GENERIC_WRITE,
                                    0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
        if(hDriver==INVALID_HANDLE_VALUE)
        {
          ShowMessage("打开设备失败.");
          DeleteService(hService);
          CloseServiceHandle(hService);
          CloseServiceHandle(hSCM);
          notifying = false;
          Button1->Enabled = true;
          Button2->Enabled = false;
          Button3->Enabled = true;
          return;
        }
        hProcessEvent = OpenEvent(SYNCHRONIZE,FALSE,"CPNDriverEvent");
        th = new GetInformationThread(true,ListView1);
        th->Resume();
        notifying = true;
        Button1->Enabled = false;
        Button2->Enabled = true;
        Button3->Enabled = false;
      }
      

  3.   

    http://www.dishou.com/news/2/79/81/qudongchengxudedongtaijiazai.html
      

  4.   

    1楼朋友给的网址打不开,
    2楼朋友给的只是普通设备驱动(非硬件设备)
    3楼给的似乎只是一个进入RING0的驱动设备代码。
    请高手继续指点:
    该设备为鼠标设备,我是在该设备上添加了一下层过滤驱动。用系统面板安装可以正常使用,但用Rundll32 Setupapi,....安装时能在注册表项里找到其安装项,但系统设备里却找不到。无法使用该驱动。