Hello geeks,
Im working on a rather unknown territory of programming ie. which I have
never done before. I have to communicate with a driver file which are
obviously written in C. To load this driver I went thru all the forums,
help, google everything on internet and finally converted the original
CPP code that was loading the driver following the standard procedures
of loading a driver ie.
1) Open service manager by using OpenSCManager API -> works fine
2) create a kernel service with CreateService API -> works fine
3) Start the service by using StartService API -> works fine
4) close service handles
5) Open the driver file by using CreateFile API -> here where the
problem starts :(
When I try to use CreateFile api it return INVALID_HANDLE_VALUE, i have
gone through piles of code on the net both covering Delphi and CPP which
use this api and Im following the same standards, but yet I can open the
device? here's the code for opening the device:
function NDISOpenControlChannel(): boolean;
var
DesiredAccess: DWORD;
ShareMode: DWORD;
lpSecurityAttributes: PSecurityAttributes;
CreationDistribution: DWORD;
FlagsAndAttributes: DWORD;
TemplateFile: THandle;
begin
DesiredAccess := (GENERIC_READ) or (GENERIC_WRITE);
ShareMode := 0;
CreationDistribution := OPEN_EXISTING;
FlagsAndAttributes := FILE_ATTRIBUTE_NORMAL;
TemplateFile := INVALID_HANDLE_VALUE;
hChannel := CreateFile(PChar('\.\NDISHook'), DesiredAccess, ShareMode,
lpSecurityAttributes, CreationDistribution, FlagsAndAttributes, 0);
//-- Special Handling For Accessing Device On Windows 2000 Terminal
Server
//-- See Microsoft KB Article 259131 for reference
if hChannel = INVALID_HANDLE_VALUE then
begin
hChannel := CreateFile(PChar('\.\Globals\NDISHook'), DesiredAccess,
ShareMode, lpSecurityAttributes, CreationDistribution,
FlagsAndAttributes, TemplateFile);
end;
if hChannel = INVALID_HANDLE_VALUE then
Result := False
else
Result := True;
end;
While I debug this code it always returns INVALID_HANDLE_VALUE I dont
seriously know why? I can startup the driver service successfully cause
I can see that driver listed in NirSoft ServiWin (nice tool to see
drivers and windows services). I use BD7 and this driver file is located
in the application directory and I dont think that can cause this issue
cause it gets loaded successfully as a driver service. Can you guys help
me what am I doing wrong here?
Thanks all,