Search code examples
c#c++.netdllcom

Merging a c executable, managed COM dll, and .Net gui


packetlistener.exe: I have a c application that actively listens and receives packets.

comwrapper.dll: A C++ COM dll that wraps the unmanaged c executable

guiapp.exe: A .NET gui that references the comwrapper.dll and uses it to display information and handle events.

The way I am currently launch the application:

  1. Start packetlistener.exe with command line argument.
  2. Start guiapp.exe

I have spent the last couple of hours trying to figure out how to package this nicely into one process.

What I have tried to do is compile packetlistener.exe as a dll and then include it in the guiapp project. However, I am completely lost regarding starting packetlistener as part of guiapp.

I am new to windows development and feel like I am doing something wrong. Am I going about this the wrong way?


Solution

  • So I ended up figuring out what I wanted to do.

    I compiled my C application into a DLL and exposed a function that would get it started.

    I then used PInvoke to call that function in a separate thread so that it can start gathering and sending packets.

    The COM DLL magically seems to referrence the C program thats running in its own thread.

    Now since I am unable to PInvoke a DLL thats embedded I had to unpack it in a temp file you can learn about that in here.

    How can I extract a file from an embedded resource and save it to disk?.

    In the end I was left with one executable.