Thread View: borland.public.delphi.nativeapi.win32
3 messages
3 total messages
Started by anithegregorian
Mon, 14 Jul 2008 13:50
Cant load driver???
Author: anithegregorian
Date: Mon, 14 Jul 2008 13:50
Date: Mon, 14 Jul 2008 13:50
61 lines
3445 bytes
3445 bytes
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,
Re: Cant load driver???
Author: Remy Lebeau (TeamB)
Date: Tue, 15 Jul 2008 07:59
Date: Tue, 15 Jul 2008 07:59
19 lines
1476 bytes
1476 bytes
"anithegregorian" <anithegregorian@hotmail.com> wrote in message news:487b5a69@newsgroups.borland.com... > ShareMode := 0; I suspect that is wrong. You are trying to open the driver for exclusive access. I think that will not work. > While I debug this code it always returns INVALID_HANDLE_VALUE > I dont seriously know why? Have you tried calling GetLastError() yet? It will tell you why. What exactly are you trying to accomplish by accessing the driver directly, instead of going through the normal NDIS APIs instead? Gambit
Re: Cant load driver???
Author: anithegregorian
Date: Tue, 15 Jul 2008 12:13
Date: Tue, 15 Jul 2008 12:13
29 lines
1998 bytes
1998 bytes
Remy Lebeau (TeamB) wrote: > "anithegregorian" <anithegregorian@hotmail.com> wrote in message > news:487b5a69@newsgroups.borland.com... > >> ShareMode := 0; > > I suspect that is wrong. You are trying to open the driver for exclusive > access. I think that will not work. > >> While I debug this code it always returns INVALID_HANDLE_VALUE >> I dont seriously know why? > > Have you tried calling GetLastError() yet? It will tell you why. > > What exactly are you trying to accomplish by accessing the driver directly, > instead of going through the normal NDIS APIs instead? > > > Gambit > > I have a project for developing Firewall application which needs a low level network access which only possible with NDIS driver. As for the problem I got the solution, the solution was that I did not specified lpSecurityAttributes as nil. the moment I declared lpSecurityAttribute := nil; It started working!!! Voila!!! Thanks for your response...
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads