Click here to Skip to main content
15,746,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Currently I have a minifilter driver coded in C but thinking I need to recode it to c++ so that I can use c++/Cli to communicate with the driver over fltsendmessage. I am stuck with this part as its a nightmare to interact between managed and unmanaged code. Im looking for relivant links or advise of how to write a wrapper dll that can be visible to my .NET application that will take care of this. the dll if im thinking right should be like the man in the middle to handle this conversion so the structs and data will be passed correctly to the .NET application. Am I on the right track and if so where do I start? I am confused with how the driver will pass the information to the c++/cli so I can get the output to my .NET application. thank you in advance!

What I have tried:

Google Search for hours but not much help with minifilter drivers
Updated 5-Oct-22 12:42pm

1 solution

I think you should first figure out how get your .net app to use a DLL written in native code. It is not terribly difficult but .net apps can not use c++ classes. The DLL has to export plain, old C functions. Here are a few articles on the topic from this site :
Mixing .NET and native code[^]
Exposing native to managed - C++/CLI vs. P/Invoke[^]
Execute Native Code From .NET[^]
Native Under Managed[^]

Once you have that figured out then you can get into the driver code. Once that is ready to go then you need to make a DLL interface for it that your .net program can use.

You can have C++ classes in your DLL but the exported interface needs to be plain C functions. Things like opaque pointers can be helpful for that and I have successfully done it in the past. I hope that helps.
Share this answer
Dale Seeley 5-Oct-22 19:41pm    
Thank you very very much for this starting point Rick. Does this mean having my driver in C code is alright and still possible to do the rest? I will read every link you have supplied. Is there any talk of a dll interface? Do you mean cli? Or what they call now clr in visual studio? Also is it best practice or just the way it's done to add the cli dll to the driver project and then make sure dependency is set in that manner?
Rick York 5-Oct-22 20:15pm    
I really do not what best practice is when it comes to drivers because I do not write drivers at that level. I have written lots and lots of drivers but they were all user-mode. If you do everything you need to do in C then that would probably be best for the driver since it will export C functions. If I am not mistaken, all of those articles discuss DLLs.
Dale Seeley 21-Oct-22 2:28am    
Hello Again Rick I have researched 6 different books on c++/cli and have a firm understanding of what it is and what it does. I have a minifilter driver coded in c++ ready and working and also have the cli project sending simple messages to the application. Now Im lost as to how to receive the messages sent by communication port. I know structs are not the same in managed code to unmanaged code and thats where c++/cli comes in right? what is ment by exported interface? how does this all fit together? thank you in advance
Dale Seeley 21-Oct-22 2:30am    
I am well aware of all the communication port connections on both sides but my .Net does not receive any messages I send with the driver so I thought It was the transition between managed and unmanaged code causing this to happen

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