473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Q: A MFC DLL being called from c#

Hiya

I have a DLL written in VC++ MFC. It contains a class. I would like to be
able to create an instance of the class from within a C# application. I
believe the only way I can do this is to use COM? I'm afraid I'm not
familiar with this technology and would appreciate any advice on how to
proceed.

As an example of what I'm trying to do and to simplify matters, let us
assume that the class I'm trying to use from the DLL in the C# application
is something trivial like:

class CMFCMyClass
{
public:
CMFCMyClass();
~CMFCMyClass();
int getNumber()
{
return 42;
};
}

Can anybody tell me how to create the DLL, using COM technology, and then
create an instance of the class in C#.

Thanks in advance

Geoff
Nov 16 '05 #1
1 3714
Geoff,

In this case, you have two options. Both require that you wrap the
object in some way to expose it in the manner you want to access it. The
best approach would be to create a managed wrapper in VC++, which would
create a managed class which accesses the unmanaged class and aggregates the
calls to the various properties/methods on the class. For more information
on how to do this, check out the article on the O'Reilly website titled
"Writing Managed Wrappers with Managed C++", located at (watch for line
wrap):

http://www.ondotnet.com/pub/a/dotnet...cpp_part3.html

The other option is to wrap the MFC object ina COM object. To do that
would be a little more complicated, as you would have to define your
interface, then create the class factory, etc, etc (which you can do through
Active Template Language very easily, btw). All in all, it's better to go
the managed wrapper route.

Once you have the wrapper, you can just set a reference, and then use
your class from C#.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Geoff Jones" <no********@email.com> wrote in message
news:41*********************@news.dial.pipex.com.. .
Hiya

I have a DLL written in VC++ MFC. It contains a class. I would like to be
able to create an instance of the class from within a C# application. I
believe the only way I can do this is to use COM? I'm afraid I'm not
familiar with this technology and would appreciate any advice on how to
proceed.

As an example of what I'm trying to do and to simplify matters, let us
assume that the class I'm trying to use from the DLL in the C# application
is something trivial like:

class CMFCMyClass
{
public:
CMFCMyClass();
~CMFCMyClass();
int getNumber()
{
return 42;
};
}

Can anybody tell me how to create the DLL, using COM technology, and then
create an instance of the class in C#.

Thanks in advance

Geoff

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: beveled edges | last post by:
I'm using the XML functions in PHP 5. The callback function I set for namespace declarations doesn't get called. Can anyone help me out? The code is: $xml = '<addressbook...
1
by: beveled edges | last post by:
I'm using the XML functions in PHP 5. The callback function I set for namespace declarations doesn't get called. Can anyone help me out? The code is: $xml = '<addressbook...
3
by: Jun | last post by:
I have following script <script> var Animal = function(name){ this.name = name; } Animal.prototype.eat = function (food) {
3
by: Richard Urwin | last post by:
I'm using C# and having problems getting the 'Parse' EventHandler of my binding object to be called. Interestingly, the 'Format' method is always called however. A code snippet: (rdDocument is a...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
35
by: Peter Oliphant | last post by:
I'm programming in VS C++.NET 2005 using cli:/pure syntax. In my code I have a class derived from Form that creates an instance of one of my custom classes via gcnew and stores the pointer in a...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
5
by: peifeng_w | last post by:
Hi, try the following code with flag=0/1/2. #include<iostream> using namespace std; #define flag 2//option:0,1,2 class C {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.