I'm trying connect with my driver where i created the SymbolicLink this way:
#include <ntifs.h>
#include <ntddk.h>
#include <windef.h>
#include <stdlib.h>
PDEVICE_OBJECT pDeviceObject;
UNICODE_STRING dev, dos;
void MyUnloadProc(IN PDRIVER_OBJECT DriverObject)
{
IoDeleteSymbolicLink(&dos);
IoDeleteDevice(DriverObject->DeviceObject);
DbgPrint("Goodbye from driver \n");
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
{
RtlInitUnicodeString(&dev, L"\\Device\\Foo");
RtlInitUnicodeString(&dos, L"\\??\\Foo");
IoCreateDevice(DriverObject, 0, &dev, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pDeviceObject);
IoCreateSymbolicLink(&dos, &dev);
DriverObject->DriverUnload = MyUnloadProc;
DbgPrint("Hello from driver \n");
return STATUS_SUCCESS;
}
All that is made above is successful, but when tried a connection always receives the INVALID_HANDLE_VALUE
error.
Why this is happening?
Here is only code that call CreateFile()
:
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows,
SysUtils;
begin
try
if CreateFile('\\.\Foo', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) = INVALID_HANDLE_VALUE then
Writeln('Ivalid handle');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
Edit:
Test enviroment:
- VMWare with Windows 7 Professional 32 bits