VhfCreate error 0xC0000010

hulirou 0 Reputation points
2025-08-24T01:25:58.4066667+00:00

I am a beginner and I plan to write a virtual driver program. But I encountered an error in the VhfCreate function: Vhf创建失败: 0xC0000010

this some code

#include <ntddk.h>
#include <wdf.h>
#include <initguid.h>
#include "Queue.h"
#include <vhf.h>
//#pragma comment(lib, "vhfkm.lib")
//#pragma comment(lib, "C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.26100.0\\km\\x64\\vhfkm.lib")
typedef struct _DEVICE_CONTEXT {
    VHFHANDLE VhfHandle;  // 存储虚拟HID设备的句柄
    // 可添加其他设备相关的状态信息,如配置参数、缓冲区等
} DEVICE_CONTEXT, * PDEVICE_CONTEXT;
// {685186F1-995E-40E4-BDD4-184723D15E94}
DEFINE_GUID(DEVICEINTERFACE,
    0x685186f1, 0x995e, 0x40e4, 0xbd, 0xd4, 0x18, 0x47, 0x23, 0xd1, 0x5e, 0x94);
UCHAR HeadSetReportDescriptor[] = {
    0x05, 0x01,         // USAGE_PAGE (Generic Desktop Controls)
    0x09, 0x0D,         // USAGE (Portable Device Buttons)
    0xA1, 0x01,         // COLLECTION (Application)
    0x85, 0x01,         //   REPORT_ID (1)
    0x05, 0x09,         //   USAGE_PAGE (Button Page)
    0x09, 0x01,         //   USAGE (Button 1 - HeadSet : middle button)
    0x09, 0x02,         //   USAGE (Button 2 - HeadSet : volume up button)
    0x09, 0x03,         //   USAGE (Button 3 - HeadSet : volume down button)
    0x15, 0x00,         //   LOGICAL_MINIMUM (0)
    0x25, 0x01,         //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,         //   REPORT_SIZE (1)
    0x95, 0x03,         //   REPORT_COUNT (3)
    0x81, 0x02,         //   INPUT (Data,Var,Abs)
    0x95, 0x05,         //   REPORT_COUNT (5)
    0x81, 0x03,         //   INPUT (Cnst,Var,Abs)
    0xC0,               // END_COLLECTION
};
// 声明获取设备上下文的宏
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_CONTEXT, DeviceGetContext)
NTSTATUS EvtDriverDeviceAdd(
    _In_    WDFDRIVER       Driver,
    _Inout_ PWDFDEVICE_INIT DeviceInit
)
{
    NTSTATUS status = STATUS_SUCCESS;
    WDF_IO_QUEUE_CONFIG IoConfig;
    WDFQUEUE Queue;
    WDF_OBJECT_ATTRIBUTES   deviceAttributes;  // WDF 设备属性
    PDEVICE_CONTEXT deviceContext;            // 设备上下文(存储 VhfHandle)
    VHF_CONFIG vhfConfig;                     // VHF 配置结构
    WDFDEVICE device;                         // WDF 设备对象
    PAGED_CODE();
    // 初始化设备对象属性,并关联设备上下文和清理
    WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT);
    //设置vhf的清理函数
    //deviceAttributes.EvtCleanupCallback = VhfSourceDeviceCleanup;
    // 创建wdf设备对象,使用带上下文属性的配置
    status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device);
    if (!NT_SUCCESS(status)) {
        KdPrint(("wdf设备创建失败 0x%08X\n", status));
        return status; // 创建失败直接返回
    }
    else {
        // 获取设备上下文(现在应该能成功获取)
        deviceContext = DeviceGetContext(device);
        // 1. 初始化 VHF 配置结构(VHF_CONFIG)
        VHF_CONFIG_INIT(&vhfConfig,
            WdfDeviceWdmGetDeviceObject(device),  // 关联的 WDM 设备对象
            sizeof(HeadSetReportDescriptor),      // 报告描述符大小
            HeadSetReportDescriptor);             // 报告描述符内容
        // 2. 调用 VhfCreate 方法创建虚拟设备
        status = VhfCreate(&vhfConfig, &deviceContext->VhfHandle);
        if (!NT_SUCCESS(status)) {
            KdPrint(("Vhf创建失败: 0x%08X\n", status));
            goto Error;
        }
        // 3. 启动虚拟 HID 设备
        status = VhfStart(deviceContext->VhfHandle);
        if (!NT_SUCCESS(status)) {
            KdPrint(("Vhf启动失败: 0x%08X\n", status));
            goto Error;
        }
        // 配置IO队列函数(取消注释即可启用)
        // WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&IoConfig, WdfIoQueueDispatchSequential);
        // IoConfig.EvtIoDeviceControl = EvtIoDeviceControl;
        // status = WdfIoQueueCreate(device, &IoConfig, WDF_NO_OBJECT_ATTRIBUTES, &Queue);
        // if (!NT_SUCCESS(status)) {
        //     KdPrint(("IO队列创建失败 0x%08X\n", status));
        // }
        // else {
        //     KdPrint(("IO队列创建完成 0x%08X\n", status));
        // }
        // 创建设备接口
        WdfDeviceCreateDeviceInterface(device, &DEVICEINTERFACE, NULL);
        return status;
    }
Error:
    return status;
}

I can't find any video tutorials, and I feel very painful. Even if it's an English tutorial, I will study very hard

Windows development | Windows Driver Kit (WDK)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tom Tran (WICLOUD CORPORATION) 810 Reputation points Microsoft External Staff
    2025-09-16T04:05:52.2633333+00:00

    Hi @hulirou ,

    Sorry for the late response.

    Thank you for sharing your code and details. I do not know much about this program, but I will help you the best I can. From my research:

    The error 0xC0000010 means STATUS_INVALID_DEVICE_REQUEST, which usually happens when the device stack is not ready for the request. For VhfCreate, this almost always means Vhf.sys (Virtual HID Framework) is not loaded as a lower filter in your device stack.

    The reasons why this happens:

    • VhfCreate needs Vhf.sys in the device stack. If your INF file does not add vhf as a LowerFilters entry, the call will fail with STATUS_INVALID_DEVICE_REQUEST.
    • Your code placement (inside EvtDriverDeviceAdd) and report descriptor look correct, so the problem is likely configuration, not code.

    You can try:


    1. Update your INF file to include VHF as a lower filter.

    Add this snippet in the .NT.HW section of your INF file:

    [HIDVHF_Inst.NT.HW]
    AddReg = HIDVHF_Inst.NT.AddReg
    [HIDVHF_Inst.NT.AddReg]
    HKR,, "LowerFilters", 0x00010000, "vhf"
    

    Where to place it: Here’s an example of the correct structure:

    [Version]
    Signature="$WINDOWS NT$"
    Class=HIDClass
    ClassGuid={745A17A0-74D3-11D0-B6FE-00A0C90F57DA}
    Provider=%ManufacturerName%
    DriverVer=09/16/2025,1.0.0.0
    
    [Manufacturer]
    %ManufacturerName%=Standard,NT$ARCH$
    
    [Standard.NT$ARCH$]
    %DeviceName%=HIDVHF_Inst, HID\MyVirtualDevice
    
    [HIDVHF_Inst.NT]
    CopyFiles=...
    
    [HIDVHF_Inst.NT.HW]
    AddReg=HIDVHF_Inst.NT.AddReg
    
    [HIDVHF_Inst.NT.AddReg]
    HKR,, "LowerFilters", 0x00010000, "vhf"
    
    [Strings]
    ManufacturerName="Your Company"
    DeviceName="Virtual HID Device"
    

    After updating, reinstall the driver and check the device stack (Device Manager → View → Devices by driver or use devcon stack) to confirm vhf is present.


    2. Link against vhfkm.lib

    Make sure your project links to vhfkm.lib (uncomment #pragma comment(lib, "vhfkm.lib") or set it in project properties).


    3. Keep VhfCreate at PASSIVE_LEVEL (your current placement is correct).


    4. Add cleanup logic:

    VOID VhfSourceDeviceCleanup(_In_ WDFOBJECT DeviceObject)
    {
        PDEVICE_CONTEXT ctx = DeviceGetContext(DeviceObject);
        if (ctx->VhfHandle != WDF_NO_HANDLE) {
            VhfDelete(ctx->VhfHandle, TRUE);
        }
    }
    

    I also managed to find some documents relating to this post, please take a look when you have the chance:

    You can change the language from English to Chinese by simply changing the "/en-us/" to "/zh-cn/" in the URL if you want. This is as many documents as I can find regarding this program.


    If you find my suggestions helpful, please kindly accept this answer so others with the same issue can find help in your post. Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.