Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. steps needed to call DeviceIoControl

steps needed to call DeviceIoControl

Scheduled Pinned Locked Moved C / C++ / MFC
helpjson
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gamitech
    wrote on last edited by
    #1

    Hello, I have designed a simple device driver that export with the help of IOCTL's some variables. I made a win 32 api that load the driver, and looks up an event in the driver. The event works just fine it signales everytime it should, but whenever I call DeviceIoControl and then I call GetLastError(), FormatMessage() I see that the error mesage is always the same: "The parameter is incorrect" . I don't know what parameter, bacause I have checked all parameters and they are all correct. Maybe I have missed something before calling DeviceIoControl function. These are the steps I considered: OpenSCManager(); CreateService(); if service already running OpenService() StartService(); CreateFile(); //get the driver's handle OpenEvent(); //get the event handle created by the driver; DeviceIoControl(); //and I get the error and then it is not important because it is not related to; Please tell me what can be wrong. the IOCTL -> CTLCODE are the same in the driver as in the aplication. I don't see what can I miss. If you want I can give you a code snippet. Thanks gabby

    D 1 Reply Last reply
    0
    • G gamitech

      Hello, I have designed a simple device driver that export with the help of IOCTL's some variables. I made a win 32 api that load the driver, and looks up an event in the driver. The event works just fine it signales everytime it should, but whenever I call DeviceIoControl and then I call GetLastError(), FormatMessage() I see that the error mesage is always the same: "The parameter is incorrect" . I don't know what parameter, bacause I have checked all parameters and they are all correct. Maybe I have missed something before calling DeviceIoControl function. These are the steps I considered: OpenSCManager(); CreateService(); if service already running OpenService() StartService(); CreateFile(); //get the driver's handle OpenEvent(); //get the event handle created by the driver; DeviceIoControl(); //and I get the error and then it is not important because it is not related to; Please tell me what can be wrong. the IOCTL -> CTLCODE are the same in the driver as in the aplication. I don't see what can I miss. If you want I can give you a code snippet. Thanks gabby

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      How are you calling DeviceIoControl()?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      G 1 Reply Last reply
      0
      • D David Crow

        How are you calling DeviceIoControl()?


        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

        G Offline
        G Offline
        gamitech
        wrote on last edited by
        #3

        int st=DeviceIoControl(hDrv, IOCTL_PROCOBSRV_ACTIVATE_MONITORING, &activateInfo, sizeof(activateInfo), NULL, 0, &ret, NULL ); gabby

        D 1 Reply Last reply
        0
        • G gamitech

          int st=DeviceIoControl(hDrv, IOCTL_PROCOBSRV_ACTIVATE_MONITORING, &activateInfo, sizeof(activateInfo), NULL, 0, &ret, NULL ); gabby

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Is this article of any help? It uses that same control code.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          G 1 Reply Last reply
          0
          • D David Crow

            Is this article of any help? It uses that same control code.


            "One must learn from the bite of the fire to leave it alone." - Native American Proverb

            G Offline
            G Offline
            gamitech
            wrote on last edited by
            #5

            hope this is good #include "stdafx.h" #include #include #include #include #pragma comment (lib,"psapi.lib") LPCTSTR GetDriverFromFilePath(LPTSTR FilePath, LPTSTR DriverName); LPCTSTR ErrorMessage(DWORD ErrorId); typedef struct _ActivateInfo { BOOLEAN bActivate; } ACTIVATE_INFO, *PACTIVATE_INFO; typedef struct _CallbackInfo { HANDLE hParentId; HANDLE hProcessId; BOOLEAN bCreate; }CALLBACK_INFO, *PCALLBACK_INFO; DWORD WINAPI Opreste(LPVOID pParam); HANDLE kmev; bool out; #define FILE_DEVICE_UNKNOWN 0x00000022 #define IOCTL_UNKNOWN_BASE FILE_DEVICE_UNKNOWN #define IOCTL_PROCOBSRV_ACTIVATE_MONITORING \ CTL_CODE(IOCTL_UNKNOWN_BASE, 0x0800, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_PROCOBSRV_GET_PROCINFO \ CTL_CODE(IOCTL_UNKNOWN_BASE, 0x0801, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) /********************************************************* * Main Function Entry * *********************************************************/ int _cdecl main(void) { WIN32_FIND_DATA fd; SC_HANDLE hSCManager; SC_HANDLE hService; FindFirstFile("*.sys",&fd); char path[1024]; GetModuleFileName(0,path,sizeof(path)); MessageBox(0,ErrorMessage(GetLastError()),"GetModuleFileName",MB_ICONINFORMATION); char DriverName[1024]; strcpy(DriverName,GetDriverFromFilePath(path,fd.cFileName)); hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); MessageBox(0,ErrorMessage(GetLastError()),"OpenSCManager",MB_ICONINFORMATION); printf("Load Driver\n"); if(hSCManager!=NULL) { printf("Create Service\n"); hService = CreateService(hSCManager,fd.cFileName,fd.cFileName,SERVICE_ALL_ACCESS,SERVICE_KERNEL_DRIVER,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL,DriverName,NULL,NULL,NULL,NULL,NULL); MessageBox(0,ErrorMessage(GetLastError()),"CreateService",MB_ICONINFORMATION); if (hService==NULL) hService=OpenService(hSCManager, fd.cFileName,SERVICE_ALL_ACCESS); MessageBox(0,ErrorMessage(GetLastError()),"OpenService",MB_ICONINFORMATION); printf("Start Service\n"); if(StartService(hService, 0, NULL)==0) { MessageBox(0,ErrorMessage(GetLastError()),"Start Service",MB_ICONINFORMATION); DeleteService(hService); CloseServiceHandle(hService); } else { SERVICE_STATUS ss; while (1) { QueryServiceStatus(hService,&ss); if (ss.dwCurrentState!=SERVICE_RUNNIN

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups