Using windows DDK with C#
For a little background story, I work in a computer lab and we need to have an easy method to disable certain network protocol bindings on adapters based on their PCI bus locations.
So far I have written a C# command line utility to find them, get their bus locations, netcfginstanceid, etc. The one thing I haven't figured out how to do is remove bindings on those adapters, I could go through and remove them in the registry but it would still show up in adapter settings.
Eventually I found out some neat utilities in the windows DDK, especially the bindview sample program, what I want to do is take the NetCfgAPI included in the bindview sample and use it in my C# program, the problem is they are C++ files. I have tried using MIDL to convert them into a .ddl or .tlb that I can then use pinvoke on but I know little about pinvoke and the MIDL compiler 开发者_如何学Gocomes up with errors such as "midl : command line error MIDL1003 : error returned by the C preprocessor (4)".
My question is, is there an easier way to do this? and if there is not, what is the best way to go about converting the NetCfgApi c++ files into something usable in C#?
I could write the utility in C++ but I am more comfortable using C#.
You could try compiling this stuff with C++/CLI as a DLL. In the project settings under compiler, mention that you do not want CLR, it will ease the compilation.
Then you should be able to add that DLL as a reference in your C# project.
Use ATL or something with C++ (not managed, straight C++) to create a COM object wrapper for the C++ code. Then use COM-interop from C# to talk to your COM object.
精彩评论