Solved

Accessing a C++ object from a C# object

Posted on 2007-04-02
6
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

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