Solved

Accessing a C++ object from a C# object

Posted on 2007-04-02
6
187 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
ID: 18838665
It depends if you can use managed C++ code or not. Why you need C++ class?
0
 

Author Comment

by:raw_enha
ID: 18838731
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
ID: 18838802
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:raw_enha
ID: 18838872
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
ID: 18838988
>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
ID: 18840480
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

13 Experts available now in Live!

Get 1:1 Help Now