Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


How to add a new device with the fakemodem.sys in the main()?

flammmableflammmable Member Posts: 4

I try to create a software virtual COM-port without the com0com or other apps. I try to use a fakemodem example. The DriverEntry(...) function is:

NTSTATUS DriverEntry(
           IN PDRIVER_OBJECT  DriverObject,
           IN PUNICODE_STRING RegistryPath
           )
{
    NTSTATUS            status = STATUS_SUCCESS;
    WDF_DRIVER_CONFIG   config;
    KdPrint(("Fakemode Function Driver Sample - Driver Framework Edition.\n"));
    KdPrint(("Built %s %s\n", __DATE__, __TIME__));
    WDF_DRIVER_CONFIG_INIT( &config, FmEvtDeviceAdd );
    status = WdfDriverCreate(
                            DriverObject,
                            RegistryPath,
                            WDF_NO_OBJECT_ATTRIBUTES,
                            &config,          // Driver Config Info
                            WDF_NO_HANDLE
                            );
    if (!NT_SUCCESS(status)) {
        KdPrint( ("WdfDriverCreate failed with status 0x%x\n", status));
    }
    return status;
}

How can I use the fakemodem driver from the main() function of my user-space application? How to add a new device with the fakemodem.sys in the main() ?

Comments

  • Nathan_KiddNathan_Kidd Member - All Emails Posts: 28
    via Email
    On 2023-01-13 6:56 a.m., flammmable wrote:

    > How can I use the fakemodem driver from the main() function of my user-space application?

    (I can't tell if this is a separate question or not. If you have a fake
    com port then you talk to the com port. If you need special
    communication you might handle IOCTLs in the driver and in usermode use
    DeviceIoControl().)

    > How to add a new device with the fakemodem.sys in the main() ?

    You use the SetupDi family of APIs. Look the devcon source for examples:
    https://github.com/microsoft/Windows-driver-samples/tree/main/setup/devcon


    -Nathan
  • flammmableflammmable Member Posts: 4

    I just want to start my console app (may be with some params) and then see appearance a new COM-port in the Windows Device Manager (without any real external devices connection, of course). Is it possible to do so with the fakemodem driver example?

  • flammmableflammmable Member Posts: 4
    edited January 13

    P.S. I have already create a Windows virtual machine (with the VirtualBox), successfully compile the fakemodem example, add the fakemodem.sys to the system (with "sc create fakemodem type= kernel binPath= path\fakemodem.sys" command) and start it with the "sc start fakemodem". I see the KdPrint output, so I need to somehow tell the driver that I want a new COM-port. Is it possible? If yes, how?

  • Nathan_KiddNathan_Kidd Member - All Emails Posts: 28
    via Email
    On 2023-01-13 10:05 a.m., flammmable wrote:
    > P.S. I have already create a Windows virtual machine (this
    > VirtualBox), successfully compile the fakemodem example, add the
    > fakemodem.sys to the system (with "sc create fakemodem type= kernel
    > binPath= \fakemodem.sys" command) and start it with the "sc start
    > fakemodem".

    Disclaimer: I don't have any experience with fakemodem or virtual com
    ports in general, and there are folks on this list with far more
    experience and authority.

    In my limited understanding, service-controlled drivers work for pure
    software functions, but if you want to interact with the PnP manager and
    show up in the device tree you need to use SetupDi. Eventually devcon
    will call newdev!UpdateDriverForPlugAndPlayDevices after which Device
    Manager shows new virtual devices. Follow what devcon install does.
    You need an inf for your sys. (I ended up with a ~300 LOC class to
    manage the complexities; not the simplest API.)

    -Nathan
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 January 2023 Live, Online
Developing Minifilters 20 March 2023 Live, Online
Internals & Software Drivers 17 April 2023 Live, Online
Writing WDF Drivers 22 May 2023 Live, Online