none
How acess my device using CreateFile() api? RRS feed

  • Question

  • I have a Delphi code where i want send a command to my driver, but CreateFile() cannot find device location.

    here is my use of CreateFile()

    hDevice := CreateFileW('\\.\XXX', GENERIC_ALL, 0,
        PSECURITY_DESCRIPTOR(nil), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    and in my device with symbolic link:

    const WCHAR deviceNameBuffer[] = L"\\Device\\XXX";
    const WCHAR deviceSymLinkBuffer[] = L"\\??\\XXX";
    PDEVICE_OBJECT g_MyDevice

    /////////////////// DriverEntry() /////////////////////

    UNICODE_STRING deviceNameUnicodeString, deviceSymLinkUnicodeString;
     
     // Normalize name and symbolic link.
     RtlInitUnicodeString (&deviceNameUnicodeString,
       deviceNameBuffer);
     RtlInitUnicodeString (&deviceSymLinkUnicodeString,
       deviceSymLinkBuffer);
     
     // Create the device.
     ntStatus = IoCreateDevice ( pDriverObject,
       0, // For driver extension
       &deviceNameUnicodeString,
       FILE_DEVICE_UNKNOWN,
       FILE_DEVICE_UNKNOWN,
       FALSE,
       &g_MyDevice);
     
     // Create the symbolic link
     ntStatus = IoCreateSymbolicLink(&deviceSymLinkUnicodeString,
       &deviceNameUnicodeString);



    Saturday, August 12, 2017 7:31 AM

All replies