Solved

Using an exported Class defined in an MFC dll in  Posted on:  04/27/2004 23:41:54

Posted on 2004-04-28
4
181 Views
Last Modified: 2010-04-15
I have a dll MyMFCDLL.dll in which a class MyExportedClass is defined. The dll is created using VC6.0. It is exported as _declspec(dllexport). I want to use this class in my C# application. how do I use it?
0
Comment
Question by:satyaswarup
[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
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
vancouver_jones earned 125 total points
ID: 10940823
A good way to use native C++ code in C# is to de-export your C++ class and wrap it into a managed C++ class that will serve as an interface to your native C++ class. Then you'll import the managed C++ class into your C# code. Here is what you'll need to do:

First create a Managed C++ Class Library Template project in Visual Studio. Before you do, be sure to read the following carefully to understand the template:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconclasslibrarytemplate.asp

You'll note that you need to convert the project to mixed mode and link in the MFC libraries as needed. (I'll leave it up to you to figure out what MFC stuff needs to be linked in) Read the following carefully:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmex/html/vcconconvertingmanagedextensionsforcprojectsfrompureintermediatelanguagetomixedmode.asp

Finally, you'll need to include most of your native C++ files into the project and create new managed C++ classes to wrap the classes you want to expose. The following article describes how:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp12192002.asp

Then you'll need to either include the new mixed DLL as a reference in your C# project or dynamically load it in some other way which is beyond the scope of this answer.

This is not the most straightfoward thing to do. It's a multi-step process. I've had to do it before which is why I can provide this information, but it took me a while to implement it in what I was doing, so keep trying if things don't go smoothly the first time.
0
 
LVL 1

Expert Comment

by:vancouver_jones
ID: 10941067
This is even better. I just found it. My situation that I described above was slightly different than yours because I had to adapt an unmanaged C++ class (not a dll) into my enviornment. This should be a TON easier for you:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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