Compile DevCon source code into a DLL

463 views
Skip to first unread message

santapanda

unread,
Mar 26, 2010, 12:41:01 PM3/26/10
to
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

unread,
Mar 26, 2010, 11:43:45 PM3/26/10
to
santapanda <santa...@discussions.microsoft.com> wrote:
>
>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.

>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, ti...@probo.com
Providenza & Boekelheide, Inc.

santapanda

unread,
Mar 29, 2010, 9:13:01 AM3/29/10
to
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!

"Tim Roberts" wrote:

> .
>

Tim Roberts

unread,
Mar 31, 2010, 1:36:08 AM3/31/10
to
santapanda <santa...@discussions.microsoft.com> wrote:
>
>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

santapanda

unread,
Mar 31, 2010, 9:54:01 AM3/31/10
to
I never said I was an experienced C# programmer.

But thanks for the links. pinvoke.net has proved extremely useful.

"Tim Roberts" wrote:

> .
>

mirce...@gmail.com

unread,
Jan 4, 2016, 12:45:01 PM1/4/16
to
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#.
Reply all
Reply to author
Forward
0 new messages