Solved

Accessing C++ code(unmanaged & if possible, managed as well) in C#

Posted on 2007-04-06
3
398 Views
Last Modified: 2013-12-17
I want to write a managed C++ class that I can then access in C# code.  The C++ class will contain unmanaged code as well.  The C++ class has to keep things in memory as well.  It's a class that deals with image manipulation, so I gotta keep a USHORT* in memory (it has to be this type or some other type that easily converts into USHORT* because we use 3rd party code for image enhancement and it requires USHORT*). So, it has to be something that can be long-lived.  When I use a function that causes the buffer to change and then use another function to access that buffer later on, i want to access the newly changed one, not a new instance.  I've tried creating an MFC DLL and just started trying to create a C++ Class library instead.  I can't get anything to work.  Can anybody give me any pointers on how to deal with this? I"ve never done cross-platform stuff before AND its also my first time working in C#.  Any help would be appreciated.  Any websites or examples you could point me towards would also be appreciated.
0
Comment
Question by:raw_enha
  • 2
3 Comments
 
LVL 16

Expert Comment

by:AlexNek
ID: 18867402
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 18868820
You need to create C++/CLI Class Library. Class exported from this library has pure .NET interface and can be accessed from any .NET language. Internally clas can allocate unmanaged resources.
C++/CLI allows to write mixed managed/unmanaged code, this technology sometimes called IJW (It Just Work). To use unmanaged code in C++/CLI project, you only need to include required h-files, add .lib files if necessary, and call unmanaged code directly.
I don't suggest you to use PInvoke because C++/CLI is much beter for interoperability.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 18868826
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issues with C++ Class 19 80
Syntax error 9 45
C# HTTP GET method sample code 3 40
free scanner TWAIN can be operated with a Web application 9 37
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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

19 Experts available now in Live!

Get 1:1 Help Now