use COM classes in a C# Winform application that are exported from another C# WinForm application

Brian Dumas
Brian Dumas used Ask the Experts™
on
Hello Experts,

Currently I have the following:

APP_A is a C# Win Form

APP_HW  is a C++ Windows Application that exposes various COM classes

This works fine, and APP_A can use the COM classes from APP_HW.


Now I want to change APP_HW from a C++ application to a C# WinForm application (I'll call it APP_HW_CS) and expose COM classes from it that can be used by APP_A. However, I do not want to use Reflection to achieve this. Reflection will just load APP_HW_CS for APP_A to use,  and I need to have APP_A link to a running APP_HW_CS for it's COM classes.

I have read a lot of information online. I have a COM object that is registered and exported from the APP_HW_CS (C# version). But the only way to use it appears to add the APP__HW_CS as a reference and then create the objects. But putting it as a reference seems to make it load a new version of APP_HW_CS and not use the running APP_HW_CS.

Is what I am trying to do even possible?

Thanks for any help and any references you can point me too.

Brian.
Using VS2013 on Windows 7 Pro 64bit.
Compiliing as a 32bit app.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
As you are rewriting is there a reason you want to use COM rather than a dll that your CS interface consumes?
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Have to agree with Andy here:  if you're rewriting this into .NET, then just add the reference directly to the rewritten project (the same way you would a DLL).
Brian DumasSenior Software Engineer

Author

Commented:
Hello Andy,

I was trying to keep this as simple as possible, but maybe I messed it up. The APP_HW_CS controls hardware that is attached. The APP_A (user application) is meant to be able to see into the APP_HW_CS and work with the hardware. So, where would the DLL be located?  And if APP_A reflects into APP_HW_CS, then it is a different APP_HW_CS than the one that is running.

Maybe you can give me an example of what you mean. Over complicating things seems to be in my nature :)

kaufmed, maybe an example???

Thanks, Brian
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Brian DumasSenior Software Engineer

Author

Commented:
Please Help .
Do I need to clarify anything about the issue/question?

Thanks, Brian
Brian DumasSenior Software Engineer

Author

Commented:
Hello Experts...anythiing?
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
I'm not sure what an example should look like:  The same way you add a reference to a DLL in .NET (i.e. by right-clicking "References" in Solution Explorer and selecting "Add Reference"), you can do the same to a .NET executable (this doesn't work for just any executable). So if you're rewriting all of the pieces into .NET code, then just reference the 2nd component within the 1st component.

For a more flexible architecture, I would refactor the common logic out into a DLL (project) that both executables referenced. This achieves the same goal as what I describe above, but it's a bit more intuitive/expected by other .NET developers--referencing a executable directly isn't done very often.
Brian DumasSenior Software Engineer

Author

Commented:
Hello kaufmed, thank you for responding.  My issue is that the user will create an object from a known assembly and then call methods using that object. My problem is that I need the execution of the method to happen in the other process.

More Detail:

The process I have running is managing hardware that our company develops (used in semiconductor testing). High voltage and high current.

The user would get an object (from the hardware process) and call functions that control the current/voltage. I cannot have the user controlling it from his/her application and talking directly to the hardware. When the user calls the function for setting voltage, that command needs to actually change the voltage in the hardware process. Not sure if I am making this any clearer :)

Thanks for the help,

Brian

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial