none
CreateFile(xxx1:) failed.

    Question

  • Hi,

    I have created a sample driver and loaded the same at boot time successfully.

     

    My question is:

    I am trying to load this driver from two of my applications. Both applications are using the CreateFile() API.

    From my first application the CreateFile() call is success and I can able to get a valid handle. 

    But while calling the same CreateFile() API from my second application It's getting failed, GetLastError value is (GetLastError() as 1012072868)

     

    Code sample:

    Application 1: (Sample.DLL) // Successful Call

      HANDLE hDS = CreateFile( TEXT("PRO1:"), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );

     

    if (INVALID_HANDLE_VALUE != hDS) //Getting VALID HANDLE 

    DeviceIoControl( hDS, IOCTL_PROXY_CALCULATE, (PBYTE) pwszName, sizeof( pwszName ), NULL, 0, &BytesHandled, NULL );

     

    if(INVALID_HANDLE_VALUE != hDS)

    CloseHandle( hDS );

     

    Application 2: (Sample.EXE) // UnSuccessful Call

      HANDLE hDS = CreateFile( TEXT("PRO1:"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );

    if (INVALID_HANDLE_VALUE != hDS)  //FAIL getting GetLastError as 1012072868 

    DeviceIoControl( hDS, IOCTL_PROXY_CALCULATE, (PBYTE) pwszName, sizeof( pwszName ), NULL, 0, &BytesHandled, NULL );

     

    if(INVALID_HANDLE_VALUE != hDS)

    CloseHandle( hDS );

     

    My Reg Entries:

    REGEDIT4 [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\ProxyDrv]

    "Dll"="ProxyDrv.dll"

    "Prefix"="PRO"

    "DeviceArrayIndex"=dword:2

     

     

    Any one please help me to figure out the problem.

     

     

    Thanks

    Shankar B.

    Monday, January 10, 2011 1:19 PM

All replies

  • To me, that is a strange error code.  How do you determine that error code?

    What does the code in your PRO_Open do?


    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman

    Eurotech Inc.
    www.Eurotech.com
    Monday, January 10, 2011 1:42 PM
  • Hi Sankar,

     

    The error code doesn't look to be meaningful, try to print it in hex code and share with us. Check in your driver XXX_Open() function, whether you had any code for restricting more than one access. You can also add some retail messages inside  that function to check the reason for failure.

    Monday, January 10, 2011 1:44 PM
  • are you running the 2 apps contemporarely? if so, can your driver be open multiple times? The diff between the two calls is in the dwDesiredAccess and dwShareMode parameter. How do you handle those in PRO_Open?

    --
    Luca Calligaris
    lucaDOTcalligarisATeurotechDOTcom
    www.eurotech.com
     
     
     
    "Sankar Balasubramanian" <=?utf-8?B?U2Fua2FyIEJhbGFzdWJyYW1hbmlhbg==?=> ha scritto nel messaggio news:dbc11c70-63fd-4385-8e24-e35fcba42ac0...

    Hi,

    I have created a sample driver and loaded the same at boot time successfully.

     

    My question is:

    I am trying to load this driver from two of my applications. Both applications are using the CreateFile() API.

    From my first application the CreateFile() call is success and I can able to get a valid handle. 

    But while calling the same CreateFile() API from my second application It's getting failed, GetLastError value is (GetLastError() as 1012072868)

     

    Code sample:

    Application 1: (Sample.DLL) // Successful Call

      HANDLE hDS = CreateFile( TEXT("PRO1:"), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );

     

    if (INVALID_HANDLE_VALUE != hDS) //Getting VALID HANDLE 

    DeviceIoControl( hDS, IOCTL_PROXY_CALCULATE, (PBYTE) pwszName, sizeof( pwszName ), NULL, 0, &BytesHandled, NULL );

     

    if(INVALID_HANDLE_VALUE != hDS)

    CloseHandle( hDS );

     

    Application 2: (Sample.EXE) // UnSuccessful Call

      HANDLE hDS = CreateFile( TEXT("PRO1:"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 );

    if (INVALID_HANDLE_VALUE != hDS)  //FAIL getting GetLastError as 1012072868 

    DeviceIoControl( hDS, IOCTL_PROXY_CALCULATE, (PBYTE) pwszName, sizeof( pwszName ), NULL, 0, &BytesHandled, NULL );

     

    if(INVALID_HANDLE_VALUE != hDS)

    CloseHandle( hDS );

     

    My Reg Entries:

    REGEDIT4 [HKEY_LOCAL_MACHINE\Drivers\BuiltIn\ProxyDrv]

    "Dll"="ProxyDrv.dll"

    "Prefix"="PRO"

    "DeviceArrayIndex"=dword:2

     

     

    Any one please help me to figure out the problem.

     

     

    Thanks

    Shankar B.


    Luca Calligaris (MVP-Windows Embedded) lucaDOTcalligarisATeurotechDOTcom www.eurotech.com
    Monday, January 10, 2011 1:50 PM
  • The error code is meaning less, can you check how are you printing it. Correct error code will defiantly provide a solid message to debug the issue.

    Looks your XXX_Open() is restricting only one process to open the device. Check it.

     

    ---Misbah

    Monday, January 10, 2011 2:13 PM
  • Hi,

    Application1 opens the device in share mode FILE_SHARE_READ|FILE_SHARE_WRITE.

    Application2 wants to OPEN_EXISTING device in share mode FILE_SHARE_READ mode.

    Now same existing instance should not be opened in different modes.

    Try to open device in Application1 with only FILE_SHARE_READ mode or try to open Application2 with FILE_SHARE_READ|FILE_SHARE_WRITE mode.

    Hope this works...

    Regards,

    Mansukh

    Tuesday, January 11, 2011 2:28 AM
  • Just to add previous info.

    OR

    Change the parameter OPEN_EXISTING to OPEN_ALWAYS in both places without changing the other parameters.

    If that works, it means there is a conflict in passing the parameters.

    Regards,

    Mansukh 

    Tuesday, January 11, 2011 3:11 AM