Link to home
Start Free TrialLog in
Avatar of raw_enha
raw_enha

asked on

Accessing a C++ object from a C# object

I want to write a C++ Class.  I want to be able to access this class from a C# project.  What's the easiest way to set up the C++ class to have it the most easily accessible from the C# object?
Avatar of AlexNek
AlexNek

It depends if you can use managed C++ code or not. Why you need C++ class?
Avatar of raw_enha

ASKER

Because I need it to work as a go between with some other C++ Classes and functions.  As long as I can use stuff like malloc, free, etc. it should be ok.  Its code to work with pointers and other data types not available to C# (USHORT, LPSTR, etc.).  Unfortunately, I can't rewrite that portion of the code, so I need to write something that will be able to deal with all that, but be accessible from C#.

Specifically, the code deals with pointers to images.  It uses third party code that cannot be re-written, therefore, it has to be in C++.  However, the application that's going to use it is in C#.
ASKER CERTIFIED SOLUTION
Avatar of AlexNek
AlexNek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There's no way to use the "Add Reference..." menu?  When I try to add the *.manifest file, it just says it can't add it and to make sure its a valid assembly or COM-component.  Is there anyway to just make it a COM-component?
>There's no way to use the "Add Reference..." menu
I think no.

>Is there anyway to just make it a COM-component?
If you have an access to C++ code, you can create an wrapper but better way is to write a wrapper in managed c++ code.
Have you thought about the possibility of making a C++ wrapper (as an assembly which uses the pinvoke to call the old legacy code) and reference the assembly from C# ?