Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

RE: Too much wired! CreateFile doesn't works

Don_Burn_1Don_Burn_1 Member Posts: 4,311
Well you create the name "ISA" but you are opening "KDISA". So you are
not opening the device you think you are.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr



> -----Original Message-----
> From: xxxxx@gmail.com [mailto:xxxxx@gmail.com]
> Posted At: Saturday, March 20, 2010 2:33 PM
> Posted To: ntdev
> Conversation: Too much wired! CreateFile doesn't works
> Subject: 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 ?
>
>
>
>
>
>
>
>
>
>
>
>
> __________ Information from ESET Smart Security, version of virus
signature
> database 4961 (20100320) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>

Comments

  • Don_Burn_1Don_Burn_1 Member Posts: 4,311
    Well you create the name "ISA" but you are opening "KDISA". So you are
    not opening the device you think you are.


    Don Burn (MVP, Windows DKD)
    Windows Filesystem and Driver Consulting
    Website: http://www.windrvr.com
    Blog: http://msmvps.com/blogs/WinDrvr

    > -----Original Message-----
    > From: xxxxx@gmail.com [mailto:xxxxx@gmail.com]
    > Posted At: Saturday, March 20, 2010 2:33 PM
    > Posted To: ntdev
    > Conversation: Too much wired! CreateFile doesn't works
    > Subject: 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 ?
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > __________ Information from ESET Smart Security, version of virus
    signature
    > database 4961 (20100320) __________
    >
    > The message was checked by ESET Smart Security.
    >
    > http://www.eset.com
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    sorry , I did a few modification in the code for post here

    both the name use in driver and in the createfile are the same
  • Don_Burn_1Don_Burn_1 Member Posts: 4,311
    If you cannot post the code, don't expect us to guess what change did
    the problem. This reminds me of a budding computer science student I
    was the grader of years ago, the third time he brought a listing and had
    me stare at it for help, then to mention a 1/2 later "Well I did make a
    change", I went to the professor to ensure he failed the course.


    Don Burn (MVP, Windows DKD)
    Windows Filesystem and Driver Consulting
    Website: http://www.windrvr.com
    Blog: http://msmvps.com/blogs/WinDrvr




    > -----Original Message-----
    > From: xxxxx@gmail.com [mailto:xxxxx@gmail.com]
    > Posted At: Saturday, March 20, 2010 3:19 PM
    > Posted To: ntdev
    > Conversation: Too much wired! CreateFile doesn't works
    > Subject: RE: Too much wired! CreateFile doesn't works
    >
    >
    >
    > 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
    >
    >
    >
    >
    >
    > __________ Information from ESET Smart Security, version of virus
    signature
    > database 4961 (20100320) __________
    >
    > The message was checked by ESET Smart Security.
    >
    > http://www.eset.com
    >
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA