Solved

Accessing a C++ object from a C# object

Posted on 2007-04-02
6
183 Views
Last Modified: 2013-12-16
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?
0
Comment
Question by:raw_enha
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:AlexNek
Comment Utility
It depends if you can use managed C++ code or not. Why you need C++ class?
0
 

Author Comment

by:raw_enha
Comment Utility
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#.
0
 
LVL 16

Accepted Solution

by:
AlexNek earned 500 total points
Comment Utility
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:raw_enha
Comment Utility
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?
0
 
LVL 16

Expert Comment

by:AlexNek
Comment Utility
>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.
0
 
LVL 1

Expert Comment

by:A_Ridiculously_Long_Unique_Name
Comment Utility
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# ?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now