Sysinternals Homepage
Forum Home Forum Home > Windows Discussions > Development
  New Posts New Posts RSS Feed - How acess my device using CreateFile() api?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How acess my device using CreateFile() api?

 Post Reply Post Reply
Author
Message
flashcoder View Drop Down
Newbie
Newbie
Avatar

Joined: 06 March 2017
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote flashcoder Quote  Post ReplyReply Direct Link To This Post Topic: How acess my device using CreateFile() api?
    Posted: 12 August 2017 at 3:31pm
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);





Edited by flashcoder - 12 August 2017 at 3:32pm
Back to Top
red-ray View Drop Down
Newbie
Newbie
Avatar

Joined: 06 June 2007
Location: England
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote red-ray Quote  Post ReplyReply Direct Link To This Post Posted: 22 September 2017 at 9:00am
I expect L"\\??\\XXX" should be L"\\DosDevices\\Global\\XXX" you should use CreateFileW( L"\\\\.\\XXX", ... ).
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.06
Copyright ©2001-2016 Web Wiz Ltd.