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
Solved

Accessing a C++ object from a C# object

Posted on 2007-04-02
6
190 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

791 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