Click here to Skip to main content
16,021,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am exposing a virtual com port as a Windows OS driver that my app needs to be able to send and receive data from.

My app a user space application, so how do I expose functions from my driver that can then be used by loading a DLL and calling some functions?

What I have tried:

I haven't tried anything yet because I'm not sure what to do.
Posted

Hello,

You can choose different ways for communication with your driver. It is also depend on what type of the driver you are going to use and the framework which you plan to use as the base. For virtual COM port enough to have UMDF driver, I think.
The basic communication level which is easy to implement for the all drivers is the IOCTL
You should define you own IOCTL control code and prepare handler in the driver (IRP_MJ_DEVICE_CONTROL). You can call DeviceIoControl to execute driver function. It also allowed to pass the parameters and receive results.
To use it you should find you device by using the SetupAPI by your driver interface. You can use the base interface in the driver (in your case it is COM port enumerator) or define your own interface for the communication(defined in inf file, you can look at the IoRegisterDeviceInterface).
If you are using the base interface you need to check the device by the hardware id (defined in inf file). After just call the CreateFile API with that interface.
In KMDF and UMDF you have predefined functions which you should override in your driver: .
For UMDF in additional you have the COM service which can support your own interface which you can use to execute specified functionality on the driver, but this will require some system privileges and may not work for the regular applications.
Another also basic method to execute driver code, but not so easy to implement is the WMI. In UMDF it is easy to integrate compare to kernel as in user space WMI worked as the COM, but also possible to have it in the kernel.
Examples how to organize IOCTL communication with the drivers you can find in my articles.
Also you can check WDK samples for implementation IQueueCallbackDeviceIoControl::OnDeviceIoControl for UMDF, EvtIoDeviceControl of the WDF_IO_QUEUE_CONFIG for KMDF and IRP_MJ_DEVICE_CONTROL handler for WDM and non-WDM drivers without frameworks.

Regards,
Maxim.
 
Share this answer
 
Comments
honey the codewitch 21-Sep-23 3:55am    
Amazing! Thank you so much!
[no name] 21-Sep-23 4:11am    
There is a virtual COM port sample here:
https://github.com/microsoft/Windows-driver-samples/tree/main/serial/VirtualSerial2

Sample IOCTL is here:
https://github.com/microsoft/Windows-driver-samples/tree/main/general/ioctl

Just compile and dive in.
Maxim Kartavenkov 21-Sep-23 6:53am    
I suggest to use VirtualSerial instead of VirtualSerial2 as first one is UMDF and second is KMDF - UMDF easy to debug and implement. You can find it in this commit
https://github.com/microsoft/Windows-driver-samples/commit/97cf5197
[no name] 21-Sep-23 7:01am    
👍
honey the codewitch 21-Sep-23 22:00pm    
I was hoping you could clarify something since I'm not seeing the sample you're suggesting.

The following is in my code. This appears to be user mode, because _KERNEL_MODE is not defined in my code. So am I already using the User Mode Driver Framework here?

#ifdef _KERNEL_MODE
#include <ntddk.h>
#else
#include <windows.h>
#endif

#include <wdf.h>
I don't have an exact answer for you but I suspect you could find one at : Windows driver samples | Microsoft Learn[^]
 
Share this answer
 
Comments
honey the codewitch 20-Sep-23 14:07pm    
That's what I've started with, but I can't find that. I'll look again.
raddevus 20-Sep-23 14:33pm    
Have you looked at the Trusted Execution Environment sample ==> https://learn.microsoft.com/en-us/windows-hardware/drivers/samples/tree-driver-samples

Then within that, (code at github) take a look at the sample test code ==> https://github.com/microsoft/Windows-driver-samples/blob/main/TrEE/Test/SampleTest.cpp

It may show you how to make the calls. Hopefully this helps.
honey the codewitch 20-Sep-23 15:08pm    
thanks. i'll give it a look

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900