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

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() ?

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

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?

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?

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