CreateFile() failed. returns ERROR_INVALID_FUNCTION

Hi all,

I am trying open the upper class(HDC) filter driver, to send IOCTL request
from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
(ERROR_INVALID_FUNCTION);

The symbolic link is created for the driver.

Any idea? Thanks for your help

hDevice = CreateFile( “\\.\tdfilter”, GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

Try this:

HANDLE hDev = CreateFile(
DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);

Mat

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of shakeel
Sent: Thursday, October 09, 2003 3:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] CreateFile() failed. returns ERROR_INVALID_FUNCTION

Hi all,

I am trying open the upper class(HDC) filter driver, to send IOCTL
request
from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
(ERROR_INVALID_FUNCTION);

The symbolic link is created for the driver.

Any idea? Thanks for your help

hDevice = CreateFile( “\\.\tdfilter”,
GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Thanks Mat,

I tried. still have the same problem. Could this be due to symbolic link.
Here is how the symbolic created in Adddevice() routine for first device object.

Thanks, Shakeel.

NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT pdo)
{ // AddDevice
PDEVICE_OBJECT fido;
PDEVICE_EXTENSION pdx;
PDEVICE_OBJECT fdo;
NTSTATUS status;
UNICODE_STRING ntDeviceName;
UNICODE_STRING symbolicLinkName;
WCHAR namebuf[80];

PAGED_CODE();
KdPrint((DRIVERNAME " - Entering AddDevice: DriverObject %8.8lX, pdo %8.8lX\n", DriverObject, pdo));

if (++inst == 1)
{ //Create symbolic link to the first device object only
// Initialize the unicode strings for DeviceName and symbolic link
//
RtlInitUnicodeString(&ntDeviceName, NTDEVICE_NAME_STRING);
RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING);
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &ntDeviceName,
GetDeviceTypeToUse(pdo), FILE_DEVICE_SECURE_OPEN, FALSE, &fido);
if (NT_SUCCESS(status))
{
NTSTATUS status1 = IoCreateSymbolicLink( &symbolicLinkName,
&ntDeviceName );
if ( !NT_SUCCESS( status1 )) {
KdPrint((“IoCreateSymbolicLink failed %x\n”, status1));
}
}
}
else {
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL,
GetDeviceTypeToUse(pdo), FILE_DEVICE_SECURE_OPEN, FALSE, &fido);
}

if (!NT_SUCCESS(status))
{ // can’t create device object
KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n", status));
return status;
} // can’t create device object

pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
// From this point forward, any error will have side effects that need to
// be cleaned up.
do
{ // finish initialization
IoInitializeRemoveLock(&pdx->RemoveLock, 0, 0, 0);
pdx->DeviceObject = fido;
pdx->Pdo = pdo;
// Add our device object to the stack and propagate critical settings
// from the immediately lower device object
fdo = IoAttachDeviceToDeviceStack(fido, pdo);
if (!fdo)
{ // can’t attach
KdPrint((DRIVERNAME " - IoAttachDeviceToDeviceStack failed\n"));
status = STATUS_DEVICE_REMOVED;
break;;
} // can’t attach
pdx->LowerDeviceObject = fdo;
// Copy the flags related to I/O buffering from the lower device object so the I/O manager
// will create the expected data structures for reads and writes.
fido->Flags |= fdo->Flags & (DO_DIRECT_IO | DO_BUFFERED_IO | DO_POWER_PAGABLE);
// Clear the “initializing” flag so that we can get IRPs
fido->Flags &= ~DO_DEVICE_INITIALIZING;
} // finish initialization
while (FALSE);

if (!NT_SUCCESS(status))
{ // need to cleanup
if (pdx->LowerDeviceObject)
IoDetachDevice(pdx->LowerDeviceObject);
if(inst)
{
RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING);
IoDeleteSymbolicLink(&symbolicLinkName);
}
IoDeleteDevice(fido);
} // need to cleanup
return status;
} // AddDevice

Mathieu Routhier wrote:
Try this:

HANDLE hDev = CreateFile(
DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);

Mat

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of shakeel
Sent: Thursday, October 09, 2003 3:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] CreateFile() failed. returns ERROR_INVALID_FUNCTION

Hi all,

I am trying open the upper class(HDC) filter driver, to send IOCTL
request
from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
(ERROR_INVALID_FUNCTION);

The symbolic link is created for the driver.

Any idea? Thanks for your help

hDevice = CreateFile( “\\.\tdfilter”,
GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

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

---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Thanks Mat,

I tried. still have the same problem. Could this be due to symbolic link.
Here is how the symbolic created in Adddevice() routine for first device object.

Thanks, Shakeel.

NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT pdo)
{ // AddDevice
PDEVICE_OBJECT fido;
PDEVICE_EXTENSION pdx;
PDEVICE_OBJECT fdo;
NTSTATUS status;
UNICODE_STRING ntDeviceName;
UNICODE_STRING symbolicLinkName;
WCHAR namebuf[80];

PAGED_CODE();
KdPrint((DRIVERNAME " - Entering AddDevice: DriverObject %8.8lX, pdo %8.8lX\n", DriverObject, pdo));

if (++inst == 1)
{ //Create symbolic link to the first device object only
// Initialize the unicode strings for DeviceName and symbolic link
//
RtlInitUnicodeString(&ntDeviceName, NTDEVICE_NAME_STRING);
RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING);
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &ntDeviceName,
GetDeviceTypeToUse(pdo), FILE_DEVICE_SECURE_OPEN, FALSE, &fido);
if (NT_SUCCESS(status))
{
NTSTATUS status1 = IoCreateSymbolicLink( &symbolicLinkName,
&ntDeviceName );
if ( !NT_SUCCESS( status1 )) {
KdPrint((“IoCreateSymbolicLink failed %x\n”, status1));
}
}
}
else {
status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL,
GetDeviceTypeToUse(pdo), FILE_DEVICE_SECURE_OPEN, FALSE, &fido);
}

if (!NT_SUCCESS(status))
{ // can’t create device object
KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n", status));
return status;
} // can’t create device object

pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
// From this point forward, any error will have side effects that need to
// be cleaned up.
do
{ // finish initialization
IoInitializeRemoveLock(&pdx->RemoveLock, 0, 0, 0);
pdx->DeviceObject = fido;
pdx->Pdo = pdo;
// Add our device object to the stack and propagate critical settings
// from the immediately lower device object
fdo = IoAttachDeviceToDeviceStack(fido, pdo);
if (!fdo)
{ // can’t attach
KdPrint((DRIVERNAME " - IoAttachDeviceToDeviceStack failed\n"));
status = STATUS_DEVICE_REMOVED;
break;;
} // can’t attach
pdx->LowerDeviceObject = fdo;
// Copy the flags related to I/O buffering from the lower device object so the I/O manager
// will create the expected data structures for reads and writes.
fido->Flags |= fdo->Flags & (DO_DIRECT_IO | DO_BUFFERED_IO | DO_POWER_PAGABLE);
// Clear the “initializing” flag so that we can get IRPs
fido->Flags &= ~DO_DEVICE_INITIALIZING;
} // finish initialization
while (FALSE);

if (!NT_SUCCESS(status))
{ // need to cleanup
if (pdx->LowerDeviceObject)
IoDetachDevice(pdx->LowerDeviceObject);
if(inst)
{
RtlInitUnicodeString(&symbolicLinkName, SYMBOLIC_NAME_STRING);
IoDeleteSymbolicLink(&symbolicLinkName);
}
IoDeleteDevice(fido);
} // need to cleanup
return status;
} // AddDevice

Mathieu Routhier wrote:
Try this:

HANDLE hDev = CreateFile(
DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
);

Mat

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of shakeel
Sent: Thursday, October 09, 2003 3:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] CreateFile() failed. returns ERROR_INVALID_FUNCTION

Hi all,

I am trying open the upper class(HDC) filter driver, to send IOCTL
request
from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
(ERROR_INVALID_FUNCTION);

The symbolic link is created for the driver.

Any idea? Thanks for your help

hDevice = CreateFile( “\\.\tdfilter”,
GENERIC_READ |
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

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

---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

Do you handle IRP_MJ_CREATE in your driver?
If so, was IRP_MJ_CREATE dispatch routine called when application calls
CreateFile() and what status is returned from the dispatch routine?

Alexei.

“shakeel” wrote in message news:xxxxx@ntdev…
>
> Hi all,
>
> I am trying open the upper class(HDC) filter driver, to send IOCTL request
> from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
> (ERROR_INVALID_FUNCTION);
>
> The symbolic link is created for the driver.
>
> Any idea? Thanks for your help
>
> hDevice = CreateFile( “\\.\tdfilter”, GENERIC_READ |
> GENERIC_WRITE,
> 0,
> NULL,
> OPEN_EXISTING,
> 0,
> NULL);
>
>

Thanks Alexei.
I wasn’t handling IRP_MJ_CREATE in my driver. Now I do. it works.

Regards, Shakeel.

Alexei Jelvis wrote:
Do you handle IRP_MJ_CREATE in your driver?
If so, was IRP_MJ_CREATE dispatch routine called when application calls
CreateFile() and what status is returned from the dispatch routine?

Alexei.

“shakeel” wrote in message news:xxxxx@ntdev…
>
> Hi all,
>
> I am trying open the upper class(HDC) filter driver, to send IOCTL request
> from user application. getting INVALID_HANDLE_VALUE. with LastError = 1
> (ERROR_INVALID_FUNCTION);
>
> The symbolic link is created for the driver.
>
> Any idea? Thanks for your help
>
> hDevice = CreateFile( “\\.\tdfilter”, GENERIC_READ |
> GENERIC_WRITE,
> 0,
> NULL,
> OPEN_EXISTING,
> 0,
> NULL);
>
>


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

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

---------------------------------
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search