Felipe
Felipe

Reputation: 21

Error Starting Windows Driver: The handle is invalid

I am a web developer that decided to venture into kernel mode development. I installed WDK 8.1, Visual Studio Professional 2013 and I set up a Windows 7 VM to debug and test my drivers.

I started with this tutorial

I download the solution and build the driver. I wasn’t able to do the deployment steps described in the tutorial so I tried to install the driver using the OSR Driver Loader

I was able to register the driver but when I try to start it I get the following error.

C:\Windows\system32>sc start KmfSmall

[SC] StartService FAILED 6:

The handle is invalid.

This is the driver's code:

#include <ntddk.h>
#include <wdf.h>

DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfSmallEvtDeviceAdd;

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT  DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
    NTSTATUS status;
    WDF_DRIVER_CONFIG config;

    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfSmall: DriverEntry\n"));
    WDF_DRIVER_CONFIG_INIT(&config, KmdfSmallEvtDeviceAdd);
    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
    return status;
}

NTSTATUS KmdfSmallEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
    NTSTATUS status;
    WDFDEVICE hDevice;
    UNREFERENCED_PARAMETER(Driver);

    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfSmall: KmdfSmallEvtDeviceAdd\n"));
    status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
    return status;
}

Upvotes: 2

Views: 3133

Answers (1)

philselmer
philselmer

Reputation: 751

I just answered what appears to be the same problem after spending a week or so trying to figure it out.

Basically boils down to the project settings missing the KMDF version.

Question: Why am I getting Error Code 6 on StartService?
Answer: https://stackoverflow.com/a/23705329/2487257

Upvotes: 3

Related Questions