Dear Friends,
I am trying to access the symbolic name assigned by Windows 2000 to my
Virtual Serial Port using the registry access function
“IoOpenDeviceRegistryKey”. But this function returns with error
STATUS_INVALID_DEVICE_REQUEST which, as per ddk documentation means that
the first parameter “DeviceObject is not a valid PDO”. I am not able to
figure out why the device object pointer passed by me to this function is
invalid. I am calling this function from my DriverEntry function after
successfully calling IoCreateDevice (I am using the same DeviceObject
poiter passed to IoCreateDevice). I am attaching a portion of the code for
examination. Any help will be greatly appreciated.
Regards,
Ganesh
////// Driver entry routine //////
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath )
{
// pointer to hold newly created Device Object - required for
// manipulating some of the DO’s parameters
PDEVICE_OBJECT DeviceObject = NULL;
// pointer to our device extension
SLXExtension *pSLXExtension;
// variable to hold result of function call
NTSTATUS status;
// unicode strings to hold the device’s NT name and the DOS (Win32) name
UNICODE_STRING NtNameString;
// Create counted unicode string of our device name
RtlInitUnicodeString( &NtNameString, NT_DEVICE_NAME);
// tell debugger your present status
KdPrint( (“SLXVirPort:Entered DriverEntry!\n”) );
// Create a new device object for the device
status = IoCreateDevice(
DriverObject, // passed by the higher level driver
sizeof(SLXExtension), // size of our global storage structure
&NtNameString, // Unicode string containing name of our
device
FILE_DEVICE_SERIAL_PORT, // Type of device
0, // additional info about device - we do not have any!
FALSE, // can have non-exclusive access
&DeviceObject // empty device object pointer which
IoCreateDevice will initialise
);
// if DO creation is successful proceed and manipulate certain parameters
in the DO
if (NT_SUCCESS(status))
{
// init our local pointer to the dev extension
pSLXExtension = (SLXExtension*)DeviceObject->DeviceExtension;
// Specify the way IO is done - Buffered IO always OR with existing value
DeviceObject->Flags |= DO_BUFFERED_IO;
// Set the DeviceType - for new unknown devices it must be between 32768
and 65535
DeviceObject->DeviceType = FILE_DEVICE_SERIAL_PORT;
// Create dispatch points for all driver all possible routines (create,
open, close, unload…)
DriverObject->DriverUnload = SLXVirPortUnload;
DriverObject->MajorFunction[IRP_MJ_WRITE] = SLXVirPortWrite;
DriverObject->MajorFunction[IRP_MJ_READ] = SLXVirPortRead;
DriverObject->MajorFunction[IRP_MJ_CREATE]= SLXVirPortOpen;
DriverObject->MajorFunction[IRP_MJ_CLOSE]= SLXVirPortClose;
DriverObject->MajorFunction[IRP_MJ_CLEANUP]= SLXVirPortCleanup;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
SLXVirPortIOCtlHandler;
DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS]= SLXVirPortFlush;
DriverObject->MajorFunction[IRP_MJ_PNP] = SLXVirPortPnpDispatch;
DriverObject->MajorFunction[IRP_MJ_POWER]=
SLXVirPortPowerDispatch;
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
SLXVirPortQueryInformationFile;
DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION]=
SLXVirPortSetInformationFile;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] =
SLXVirPortSystemControlDispatch;
DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
SLXVirPortInternalIoControl;
// just to say things are fine till here!
KdPrint( (“SLXVirPort: Completed Dispatch Functions mapping!\n”) );
/******************************************************************/
// create a handle to access our registry area
status = IoOpenDeviceRegistryKey(DeviceObject),
LUGPLAY_REGKEY_DEVICE, STANDARD_RIGHTS_READ, &keyHandle);
if (status != STATUS_SUCCESS)
{
KdPrint(("SlxVirPort:IoOpenDeviceRegistryKey failed: "));
if( status == STATUS_INVALID_PARAMETER )
{
KdPrint((“STATUS_INVALID_PARAMETER Error\n”)); }
else if( status == STATUS_INVALID_DEVICE_REQUEST )
{
KdPrint((“STATUS_INVALID_DEVICE_REQUEST Error\n”)); }
else
{
KdPrint((“Unknown Error\n”)); }
}
else
{
KdPrint((“SlxVirPort:IoOpenDeviceRegistryKey success\n”)); }
/******************************************************************/
if( !NT_SUCCESS (status) )
{
// if unable to create symbolic link object exit agter deleting the
DO
KdPrint( (“SLXVirPort:Couldn’t create the symbolic link!\n”) );
IoDeleteDevice( DriverObject->DeviceObject );
}
else
{
KdPrint( (“SLXVirPort:All initialized - Symbolic link object
created \n”) );
}
// do some variable initialisation
pSLXExtension->pSerialFileObject = NULL;
pSLXExtension->pSerialDeviceObject = NULL;
pSLXExtension->IsrWaitMask = 0;
pSLXExtension->PortOpened = FALSE;
}
else
{
// unable to create device - exit - no cleanup required
KdPrint( (“SLXVirPort:Couldn’t create the device\n”) );
}
return status;
}