How to get the hDevice parameter?

hi all:
I’m writing a filter driver.Now i want to pass something to the
filter driver in an application.I think DeviceIoControl() can help to do
that.But I don’t know how to get the value of hDevice.What should I do ?
Thanks!

Jim


ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn

You need to create a device (IoCreateDevice) and a symbolic link (IoCreateSymbolicLink) in the driver. In application you need to use CreateFile API to open the symbolic link you created in driver. CreateFile returns hDevice.

-Srin.

-----Original Message-----
From: Zhong Jim [mailto:xxxxx@hotmail.com]
Sent: Sunday, June 08, 2003 8:18 AM
To: File Systems Developers
Subject: [ntfsd] How to get the hDevice parameter?

hi all:
I’m writing a filter driver.Now i want to pass something to the
filter driver in an application.I think DeviceIoControl() can help to do
that.But I don’t know how to get the value of hDevice.What should I do ?
Thanks!

Jim


???ѽ??н???ʹ?? MSN Messenger: http://messenger.msn.com/cn


You are currently subscribed to ntfsd as: xxxxx@nai.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi:
I met some trobule in handling my filter driver.
In driver’s DriverEntry() I found such sentences:

#define SFILTER_DOS_DRV_NAME L"\DosDevices\SampleFilterDrv"
RtlInitUnicodeString(&UserVisibleName, SFILTER_DOS_DRV_NAME);
IoCreateSymbolicLink(&UserVisibleName, &DriverDeviceName);

So in my application I try to get the handle of my filter driver in
this way:

char DriverName=“\DosDevices\SampleFilterDrv”;
HANDLE DriverHandle=NULL;
DriverHandle=CreateFile(
DriverName,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING,NULL);

But the returned DriverHandle always equals INVALID_HANDLE_VALUE.The
Errocode returned from GetLastError() is ERROR_PATH_NOT_FOUND.
Could you tell me where i’m wrong?
Thanks!

Jim

From:
>Reply-To: “File Systems Developers”
>To: “File Systems Developers”
>Subject: [ntfsd] RE: How to get the hDevice parameter?
>Date: Sun, 8 Jun 2003 10:44:27 -0500
>
>You need to create a device (IoCreateDevice) and a symbolic link
(IoCreateSymbolicLink) in the driver. In application you need to use
CreateFile API to open the symbolic link you created in driver. CreateFile
returns hDevice.
>
>-Srin.
>
> > -----Original Message-----
> > From: Zhong Jim [mailto:xxxxx@hotmail.com]
> > Sent: Sunday, June 08, 2003 8:18 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How to get the hDevice parameter?
> >
> > hi all:
> > I’m writing a filter driver.Now i want to pass something to the
> > filter driver in an application.I think DeviceIoControl() can help to
do
> > that.But I don’t know how to get the value of hDevice.What should I do
?
> > Thanks!
> >
> > Jim
> >
> >
> > ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger:
http://messenger.msn.com/cn
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@nai.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>—
>You are currently subscribed to ntfsd as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£ http://www.hotmail.com

Here’s a cut from the Filemon source
(www.sysinternals.com):

/****************************************************************************
*
* FUNCTION: OpenDevice( IN LPCTSTR, HANDLE *)
*
* PURPOSE: Opens the device and returns a handle if
desired.
*
****************************************************************************/
BOOL OpenDevice( IN LPCTSTR DriverName, HANDLE *
lphDevice )
{
TCHAR completeDeviceName[64];
HANDLE hDevice;

//
// Create a \.\XXX device name that CreateFile
can use
//
// NOTE: We’re making an assumption here that the
driver
// has created a symbolic link using it’s
own name
// (i.e. if the driver has the name “XXX” we
assume
// that it used IoCreateSymbolicLink to
create a
// symbolic link “\DosDevices\XXX”. Usually,
there
// is this understanding between related
apps/drivers.
//
// An application might also peruse the
DEVICEMAP
// section of the registry, or use the
QueryDosDevice
// API to enumerate the existing symbolic
links in the
// system.
//

if( (GetVersion() & 0xFF) >= 5 ) {

//
// We reference the global name so that the
application can
// be executed in Terminal Services sessions on
Win2K
//
wsprintf( completeDeviceName,
TEXT(“\\.\Global\%s”), DriverName );

} else {

wsprintf( completeDeviceName, TEXT(“\\.\%s”),
DriverName );
}
hDevice = CreateFile( completeDeviceName,
GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);
if ( hDevice == ((HANDLE)-1) )
return FALSE;

// If user wants handle, give it to them. Otherwise,
just close it.
if ( lphDevice )
*lphDevice = hDevice;
else
CloseHandle( hDevice );

return TRUE;
}

Randy

— Zhong Jim wrote:
> Hi:
> I met some trobule in handling my filter driver.
> In driver’s DriverEntry() I found such
> sentences:
>
> #define SFILTER_DOS_DRV_NAME
> L"\DosDevices\SampleFilterDrv"
> RtlInitUnicodeString(&UserVisibleName,
> SFILTER_DOS_DRV_NAME);
> IoCreateSymbolicLink(&UserVisibleName,
> &DriverDeviceName);
>
> So in my application I try to get the handle of
> my filter driver in
> this way:
>
> char
> DriverName=“\DosDevices\SampleFilterDrv”;
> HANDLE DriverHandle=NULL;
> DriverHandle=CreateFile(
>
DriverName,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING,NULL);
>
> But the returned DriverHandle always equals
> INVALID_HANDLE_VALUE.The
> Errocode returned from GetLastError() is
> ERROR_PATH_NOT_FOUND.
> Could you tell me where i’m wrong?
> Thanks!
>
>
> Jim
>
>
> >From:
> >Reply-To: “File Systems Developers”
>
> >To: “File Systems Developers”
> >Subject: [ntfsd] RE: How to get the hDevice
> parameter?
> >Date: Sun, 8 Jun 2003 10:44:27 -0500
> >
> >You need to create a device (IoCreateDevice) and a
> symbolic link
> (IoCreateSymbolicLink) in the driver. In application
> you need to use
> CreateFile API to open the symbolic link you created
> in driver. CreateFile
> returns hDevice.
> >
> >-Srin.
> >
> > > -----Original Message-----
> > > From: Zhong Jim [mailto:xxxxx@hotmail.com]
> > > Sent: Sunday, June 08, 2003 8:18 AM
> > > To: File Systems Developers
> > > Subject: [ntfsd] How to get the hDevice
> parameter?
> > >
> > > hi all:
> > > I’m writing a filter driver.Now i want to
> pass something to the
> > > filter driver in an application.I think
> DeviceIoControl() can help to
> do
> > > that.But I don’t know how to get the value of
> hDevice.What should I do
> ?
> > > Thanks!
> > >
> > > Jim
> > >
> > >
>

> > > ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger:
> http://messenger.msn.com/cn
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntfsd as:
> xxxxx@nai.com
> > > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> >
> >
> >—
> >You are currently subscribed to ntfsd as:
> xxxxx@hotmail.com
> >To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>

> ÏíÓÃÊÀ½çÉÏ×î´óµÄµç×ÓÓʼþϵͳ¡ª MSN Hotmail¡£
> http://www.hotmail.com
>
>
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook™.
http://calendar.yahoo.com

In your application use
“\\.\SampleFilterDrv”

-Srin.

-----Original Message-----
From: Zhong Jim [mailto:xxxxx@hotmail.com]
Sent: Monday, June 09, 2003 11:31 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to get the hDevice parameter?

Hi:
I met some trobule in handling my filter driver.
In driver’s DriverEntry() I found such sentences:

#define SFILTER_DOS_DRV_NAME L"\DosDevices\SampleFilterDrv"
RtlInitUnicodeString(&UserVisibleName, SFILTER_DOS_DRV_NAME);
IoCreateSymbolicLink(&UserVisibleName, &DriverDeviceName);

So in my application I try to get the handle of my filter driver in
this way:

char DriverName=“\DosDevices\SampleFilterDrv”;
HANDLE DriverHandle=NULL;
DriverHandle=CreateFile(
DriverName,GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING,NULL);

But the returned DriverHandle always equals INVALID_HANDLE_VALUE.The
Errocode returned from GetLastError() is ERROR_PATH_NOT_FOUND.
Could you tell me where i’m wrong?
Thanks!

Jim

From:
>Reply-To: “File Systems Developers”
>To: “File Systems Developers”
>Subject: [ntfsd] RE: How to get the hDevice parameter?
>Date: Sun, 8 Jun 2003 10:44:27 -0500
>
>You need to create a device (IoCreateDevice) and a symbolic link
(IoCreateSymbolicLink) in the driver. In application you need to use
CreateFile API to open the symbolic link you created in driver. CreateFile
returns hDevice.
>
>-Srin.
>
> > -----Original Message-----
> > From: Zhong Jim [mailto:xxxxx@hotmail.com]
> > Sent: Sunday, June 08, 2003 8:18 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How to get the hDevice parameter?
> >
> > hi all:
> > I’m writing a filter driver.Now i want to pass something to the
> > filter driver in an application.I think DeviceIoControl() can help to
do
> > that.But I don’t know how to get the value of hDevice.What should I do
?
> > Thanks!
> >
> > Jim
> >
> >
> > ???ѽ??н???ʹ?? MSN Messenger:
http://messenger.msn.com/cn
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@nai.com
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>—
>You are currently subscribed to ntfsd as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com


???ĵ???ʼ?ϵͳ?? MSN Hotmail?? http://www.hotmail.com


You are currently subscribed to ntfsd as: xxxxx@nai.com
To unsubscribe send a blank email to xxxxx@lists.osr.com