Discussion:
Compile DevCon source code into a DLL
(too old to reply)
santapanda
2010-03-26 16:41:01 UTC
Permalink
Raw Message
Hello,

I am trying to automate DevCon's functionality into a C# program. Instead
of accessing DevCon.exe directly using Process threads, I want to instead
call the commands directly from my project, and therefore eliminate having to
distribute DevCon.exe with my application.

I initially set this question in a .NET forum, and a responder suggested I
compile the source code into a DLL, and import that into my C# project. I'm
new to C++, and I am not sure the best way to do this.

I'd appreciate any assistance.
Tim Roberts
2010-03-27 03:43:45 UTC
Permalink
Raw Message
Post by santapanda
I am trying to automate DevCon's functionality into a C# program. Instead
of accessing DevCon.exe directly using Process threads, I want to instead
call the commands directly from my project, and therefore eliminate having to
distribute DevCon.exe with my application.
That's exactly why the source code for devcon is included in the DDK. It's
a sample. You're supposed to use the code as a recipe. The license
doesn't allow you to ship the executable with your app.
Post by santapanda
I initially set this question in a .NET forum, and a responder suggested I
compile the source code into a DLL, and import that into my C# project. I'm
new to C++, and I am not sure the best way to do this.
Surely you aren't trying to incorporate the ENTIRE functionality of devcon
into your C# program. You just need a couple of functions, right? All you
need to do is write P/Invoke headers for the SetupDi calls you need, and
convert the C++ code to C#. It's mostly a 1-to-1 conversion.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
santapanda
2010-03-29 13:13:01 UTC
Permalink
Raw Message
Thanks Tim,

I've never used P/Invoke before. Could you give me a quick example on how
to call one of the functions you mentioned in my C# code?

Thanks!
Post by Tim Roberts
Post by santapanda
I am trying to automate DevCon's functionality into a C# program. Instead
of accessing DevCon.exe directly using Process threads, I want to instead
call the commands directly from my project, and therefore eliminate having to
distribute DevCon.exe with my application.
That's exactly why the source code for devcon is included in the DDK. It's
a sample. You're supposed to use the code as a recipe. The license
doesn't allow you to ship the executable with your app.
Post by santapanda
I initially set this question in a .NET forum, and a responder suggested I
compile the source code into a DLL, and import that into my C# project. I'm
new to C++, and I am not sure the best way to do this.
Surely you aren't trying to incorporate the ENTIRE functionality of devcon
into your C# program. You just need a couple of functions, right? All you
need to do is write P/Invoke headers for the SetupDi calls you need, and
convert the C++ code to C#. It's mostly a 1-to-1 conversion.
--
Providenza & Boekelheide, Inc.
.
Tim Roberts
2010-03-31 05:36:08 UTC
Permalink
Raw Message
Post by santapanda
I've never used P/Invoke before. Could you give me a quick example on how
to call one of the functions you mentioned in my C# code?
It's hard to imagine that any relatively experienced C# programmer has
never had to call into a DLL to use one of the Win32 APIs. It's very, very
common. There's even a website that gives you the PInvoke declaration for
all of the Win32 APIs -- www.pinvoke.net.

http://www.netomatix.com/Development/SetupApi.aspx
http://www.drdobbs.com/article/printableArticle.jhtml?articleId=184416423&dept_url=/windows/
http://bytes.com/topic/c-sharp/answers/656850-disabling-devices-calling-setupapi-dll-converting-devcon-c
http://jo0ls-dotnet-stuff.blogspot.com/2009/01/enabledisable-device-programmatically.html
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
santapanda
2010-03-31 13:54:01 UTC
Permalink
Raw Message
I never said I was an experienced C# programmer.

But thanks for the links. pinvoke.net has proved extremely useful.
Post by Tim Roberts
Post by santapanda
I've never used P/Invoke before. Could you give me a quick example on how
to call one of the functions you mentioned in my C# code?
It's hard to imagine that any relatively experienced C# programmer has
never had to call into a DLL to use one of the Win32 APIs. It's very, very
common. There's even a website that gives you the PInvoke declaration for
all of the Win32 APIs -- www.pinvoke.net.
http://www.netomatix.com/Development/SetupApi.aspx
http://www.drdobbs.com/article/printableArticle.jhtml?articleId=184416423&dept_url=/windows/
http://bytes.com/topic/c-sharp/answers/656850-disabling-devices-calling-setupapi-dll-converting-devcon-c
http://jo0ls-dotnet-stuff.blogspot.com/2009/01/enabledisable-device-programmatically.html
--
Providenza & Boekelheide, Inc.
.
m***@gmail.com
2016-01-04 17:44:56 UTC
Permalink
Raw Message
Hi!
I just started a little project for a simple app (I'm an absolute beginner) and I ran in some problems using Devcon with Process and I'd like to know how you integrated its functionalities in C#.
Loading...