steps needed to call DeviceIoControl
-
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
-
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
How are you calling
DeviceIoControl()
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
How are you calling
DeviceIoControl()
?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
int st=DeviceIoControl(hDrv, IOCTL_PROCOBSRV_ACTIVATE_MONITORING, &activateInfo, sizeof(activateInfo), NULL, 0, &ret, NULL ); gabby
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
-
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
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