Too much wired! CreateFile doesn't works

#define NT_DEVICE_NAME L"\Device\ISA"
#define DOS_DEVICE_NAME L"\DosDevices\ISA"

/**********************************************************************/
// Initialise NT and Symbolic link names
UNICODE_STRING ntDeviceName ;
UNICODE_STRING win32DeviceName ;

//???
RtlInitUnicodeString( &ntDeviceName , NT_DEVICE_NAME ) ;

//???
// RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );
RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );

// Create our device ???
KdPrint( ( " Call IoCreateDevice … \n\n") );
status = IoCreateDevice( pDriverObject ,
sizeof( ISA_DEVICE_EXTENSION ) ,
&ntDeviceName ,
FILE_DEVICE_UNKNOWN ,
0 ,
FALSE ,
&fdo ) ;
if ( !NT_SUCCESS( status ) ) // can’t create device object
{

KdPrint( ( "IoCreateDevice failed - %x … \n\n " , status ) ) ;
KdPrint( ( “Could not create device \n\n”) ) ;

return status;

}
else
{
KdPrint( ( “IoCreateDevice Success - %x\n\n\n” , status ) ) ;

}

status = IoCreateSymbolicLink( &win32DeviceName , &ntDeviceName ) ;
if (!NT_SUCCESS(status))
{

KdPrint( ( “IoCreateSymbolicLink failed. Status = 0x%x\n\n\n”, status )) ;
IoDeleteDevice( fdo );

// Indicate load failure to the I/O manager; driver image is deleted…

return status ;
}
else
{
KdPrint( ( “IoCreateSymbolicLink Success - %x\n\n\n” , status ) ) ;
}

/***************************************************************/

I have installed the dirver , and I can see it in the WinObj.exe ,

then I run the test APP

/**********************************************************************/
void CISATestDlg::OnButton1()
{
// TODO: Add your control notification handler code here

int TestNo = 1;
DWORD error = 0 ;

printf(“\nTest\n”);

/////////////////////////////////////////////////////////////////////////
// Open device at IO ports 0x0378-0x37A and IRQ7

printf(“\nTest %d\n”,TestNo++);
HANDLE hPhdIo = CreateFile( “\\.\KDISA”,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING, //OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL,
NULL);

if( hPhdIo == INVALID_HANDLE_VALUE )
{

error = GetLastError() ;

printf(“XXX Could not open device\n”);
// AfxMessageBox(" Could not open device ");

int x = 0 ;

}
else
{

AfxMessageBox(" open device OK ");

}

}
/**********************************************************************/

the hPhdIo = 0XFFFFFFFF, and GetLastError( ) return 2

what is the problem ?

The name you are passing to createfile is kdisa, which is not the sym link name you created.

d

tiny phone keyboard + fat thumbs = you do the muth

-----Original Message-----
From: xxxxx@gmail.com
Sent: Saturday, March 20, 2010 11:34 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Too much wired! CreateFile doesn’t works

#define NT_DEVICE_NAME L"\Device\ISA"
#define DOS_DEVICE_NAME L"\DosDevices\ISA"

//
// Initialise NT and Symbolic link names
UNICODE_STRING ntDeviceName ;
UNICODE_STRING win32DeviceName ;

//???
RtlInitUnicodeString( &ntDeviceName , NT_DEVICE_NAME ) ;

//???
// RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );
RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );

// Create our device ???
KdPrint( ( " Call IoCreateDevice … \n\n") );
status = IoCreateDevice( pDriverObject ,
sizeof( ISA_DEVICE_EXTENSION ) ,
&ntDeviceName ,
FILE_DEVICE_UNKNOWN ,
0 ,
FALSE ,
&fdo ) ;
if ( !NT_SUCCESS( status ) ) // can’t create device object
{

KdPrint( ( "IoCreateDevice failed - %x … \n\n " , status ) ) ;
KdPrint( ( “Could not create device \n\n”) ) ;

return status;

}
else
{
KdPrint( ( “IoCreateDevice Success - %x\n\n\n” , status ) ) ;

}

status = IoCreateSymbolicLink( &win32DeviceName , &ntDeviceName ) ;
if (!NT_SUCCESS(status))
{

KdPrint( ( “IoCreateSymbolicLink failed. Status = 0x%x\n\n\n”, status )) ;
IoDeleteDevice( fdo );

// Indicate load failure to the I/O manager; driver image is deleted…

return status ;
}
else
{
KdPrint( ( “IoCreateSymbolicLink Success - %x\n\n\n” , status ) ) ;
}

/
/

I have installed the dirver , and I can see it in the WinObj.exe ,

then I run the test APP

/
/
void CISATestDlg::OnButton1()
{
// TODO: Add your control notification handler code here

int TestNo = 1;
DWORD error = 0 ;

printf(“\nTest\n”);

/////////////////////////////////////////////////////////////////////////
// Open device at IO ports 0x0378-0x37A and IRQ7

printf(“\nTest %d\n”,TestNo++);
HANDLE hPhdIo = CreateFile( “\\.\KDISA”,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING, //OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL,
NULL);

if( hPhdIo == INVALID_HANDLE_VALUE )
{

error = GetLastError() ;

printf(“XXX Could not open device\n”);
// AfxMessageBox(" Could not open device “);

int x = 0 ;

}
else
{

AfxMessageBox(” open device OK ");

}

}
/
*******/

the hPhdIo = 0XFFFFFFFF, and GetLastError( ) return 2

what is the problem ?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Let me see if I understand the code you posted correctly:

  1. You create a device with a symbolic link named “\DosDevices\ISA”
  2. You try to open that device from user mode using the name “\\.\KDISA”
  3. And you can’t see why it doesn’t work

Is this correct?

Jan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-405658-
xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Saturday, March 20, 2010 11:33 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Too much wired! CreateFile doesn’t works

#define NT_DEVICE_NAME L"\Device\ISA"
#define DOS_DEVICE_NAME L"\DosDevices\ISA"

/****************************************************************
******/
// Initialise NT and Symbolic link names
UNICODE_STRING ntDeviceName ;
UNICODE_STRING win32DeviceName ;

//???
RtlInitUnicodeString( &ntDeviceName , NT_DEVICE_NAME ) ;

//???
// RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );
RtlInitUnicodeString( &win32DeviceName , DOS_DEVICE_NAME );

// Create our device ???
KdPrint( ( " Call IoCreateDevice … \n\n") );
status = IoCreateDevice( pDriverObject ,
sizeof(
ISA_DEVICE_EXTENSION
) ,
&ntDeviceName ,
FILE_DEVICE_UNKNOWN
,
0 ,
FALSE ,
&fdo ) ;
if ( !NT_SUCCESS( status ) ) // can’t create device object
{

KdPrint( ( "IoCreateDevice failed - %x … \n\n " ,
status ) ) ;
KdPrint( ( “Could not create device \n\n”) ) ;

return status;

}
else
{
KdPrint( ( “IoCreateDevice Success - %x\n\n\n” , status )
) ;

}

status = IoCreateSymbolicLink( &win32DeviceName , &ntDeviceName
) ;
if (!NT_SUCCESS(status))
{

KdPrint( ( “IoCreateSymbolicLink failed. Status =
0x%x\n\n\n”, status )) ;
IoDeleteDevice( fdo );

// Indicate load failure to the I/O manager; driver image
is deleted…

return status ;
}
else
{
KdPrint( ( “IoCreateSymbolicLink Success - %x\n\n\n” ,
status ) ) ;
}

/***************************************************************/

I have installed the dirver , and I can see it in the WinObj.exe ,

then I run the test APP

/**********************************************************************
/
void CISATestDlg::OnButton1()
{
// TODO: Add your control notification handler code here

int TestNo = 1;
DWORD error = 0 ;

printf(“\nTest\n”);

/////////////////////////////////////////////////////////////////
////////
// Open device at IO ports 0x0378-0x37A and IRQ7

printf(“\nTest %d\n”,TestNo++);
HANDLE hPhdIo = CreateFile( “\\.\KDISA”,

GENERIC_READ|GENERIC_WRITE,
0,
NULL,

OPEN_EXISTING,

//OPEN_EXISTING

FILE_ATTRIBUTE_NORMAL,

NULL);

if( hPhdIo == INVALID_HANDLE_VALUE )
{

error = GetLastError() ;

printf(“XXX Could not open device\n”);
// AfxMessageBox(" Could not open device ");

int x = 0 ;

}
else
{

AfxMessageBox(" open device OK ");

}

}
/**********************************************************************
/

the hPhdIo = 0XFFFFFFFF, and GetLastError( ) return 2

what is the problem ?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

sorry , I did a few modification in the code for post here

both the name used in driver and in the createfile are the same

Can you see any problems ?

I just reinstall the XP , and nothing improved , all the same