473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET calling VC6 dll that uses MFC

I have a .NET managed C++ application that needs to call a 3rd party
dll that was built with VC6 and returns MFC types. e.g.

int GetSomeStrings( CStringArray *pStringArray);

The problem I'm having is the destructor of the CStringArray is
crashing. Is it possible to call VC6 dlls that use MFC from .NET?

Thanks

Mar 20 '06 #1
3 2258
> I have a .NET managed C++ application that needs to call a 3rd party
dll that was built with VC6 and returns MFC types. e.g.

int GetSomeStrings( CStringArray *pStringArray);

The problem I'm having is the destructor of the CStringArray is
crashing. Is it possible to call VC6 dlls that use MFC from .NET?


Seeing as no answered yet I'll take a shot.

your dll is built against MFC42.
VS2005 ships with MFC80.

The first problem is that the types don't match, which can be a problem
especially in constructors and destructors since that is where most
allocation/deallocation is done.

Maybe you could try (don't know if it will work or not) to point your
include and lib directories for that project to the VC6 folders. However that
would still mean they use a different CRT runtime version.

And that is the second problem.
assuming you would get it to work, the limitation is that none of the 2
components should allocate or deallocate memory of an object that was created
in the other component.

If your dll adds elements to an array, which is then deleted by your VC2005
program, your program crashes because it will try to delete memory that it
does not own. The same goes for modifying string data etc. anything in your
dll that allocates or deallocates memory in an object that was created by
your app.

The best option would be to recompile the dll in VS2005, if possible.

This is the general problem with dlls. in order to keep them portable across
multiple compiler versions you have to restrict it to only use C style
functions, and always keep memory ownership inside the component where it was
allocated.

--

Kind regards,
Bruno.
br************* *********@hotma il.com
Remove only "_nos_pam"
Mar 21 '06 #2
ge******@gmail. com wrote:
I have a .NET managed C++ application that needs to call a 3rd party
dll that was built with VC6 and returns MFC types. e.g.

int GetSomeStrings( CStringArray *pStringArray);

The problem I'm having is the destructor of the CStringArray is
crashing. Is it possible to call VC6 dlls that use MFC from .NET?


To reuse such a DLL without rebuilding it with VC8, I'd recommend something
like the following:

Design a wrapper DLL with a pure C interface that never passes CRT, MFC, ATL
or STL objects across the DLL interface. You'll need to come up with
suitable wrappers for all of the public functions of the DLL you're trying
to re-use.

Build that wrapper DLL using VC6 (so it's built w/MFC42 and the VC6 CRT),
then use that wrapper (and, indirectly, your VC6 MFC DLL) from your VC8
program.

If there's a very large interface to the DLL, this could get to be a lot of
work - but in general, you can't mix MFC, ATL or STL from different compiler
versions, so if you can't rebuild the DLL with VC8, this might be your best
shot.

-cd
Mar 21 '06 #3
Hi,

Do you have a small example for building a wrapper dll. This would be of a
great help for reference.

Thanks,
-Asfar

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:uc******** ******@TK2MSFTN GP12.phx.gbl...
ge******@gmail. com wrote:
I have a .NET managed C++ application that needs to call a 3rd party
dll that was built with VC6 and returns MFC types. e.g.

int GetSomeStrings( CStringArray *pStringArray);

The problem I'm having is the destructor of the CStringArray is
crashing. Is it possible to call VC6 dlls that use MFC from .NET?


To reuse such a DLL without rebuilding it with VC8, I'd recommend
something like the following:

Design a wrapper DLL with a pure C interface that never passes CRT, MFC,
ATL or STL objects across the DLL interface. You'll need to come up with
suitable wrappers for all of the public functions of the DLL you're trying
to re-use.

Build that wrapper DLL using VC6 (so it's built w/MFC42 and the VC6 CRT),
then use that wrapper (and, indirectly, your VC6 MFC DLL) from your VC8
program.

If there's a very large interface to the DLL, this could get to be a lot
of work - but in general, you can't mix MFC, ATL or STL from different
compiler versions, so if you can't rebuild the DLL with VC8, this might be
your best shot.

-cd

Mar 23 '06 #4

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

Similar topics

4
2433
by: jarmopy | last post by:
Hi, I have made a service with C# and calling that service class from another C# program with remoting. (Referendes from the calling program) That service class is configured so that garpage collection is not used in this class. (singleton class + override InitializeLifetimeService ) The service class uses C++ unmanaged function from dll (using DLLimport).
8
2968
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int p3); The parameters here can be read either in the forward order from p1 till p3 or reverse order from p3 till p1. Can anyone explain what is the advantage/disadvantage of either of
7
6609
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is written in C++ and it's calling a java application. This application displays a window and pushing a button is calling back the c++-plugin again.
19
4268
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
16
2308
by: aarklon | last post by:
Hi folks, recently i read the book named assembly language step by step by Jeff Duntemann. in the chapter coding for linux, he has got a paragraph named C calling conventions, which he describes as follows 1)
5
3446
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
2
2818
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors, messages, etc: // If this parameter is NULL, // GetModuleHandle returns a handle of the file used // to create the calling process. hInstExe = GetModuleHandle( NULL ); if( hInstExe!=NULL )
1
1401
by: | last post by:
I'm trying to think something through and am wondering if may have some suggestions. I am building a Windows service (VStudio 2005, C#) that uses a COM component to answer a telephone call(s). The aqpplication uses 6 trunk channels for the lines. What I need to do is initialize all 6 lines and set the event handler to witfor/answer the call. I have to pass the trun kchannel to this thread as a parameter. Then, when the phone rings on...
10
3268
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
6
11582
by: Ole Nielsby | last post by:
VC has a __cdecl specifier which allows functions and methods to be called with varying parameter count. (I understand this is the default for functions in general but in VC, instances use another convention unless they have an ellipsis argument.) I can force GCC and other compilers to use such a convention by declaring all methods with an ellipsis, but I'd rather not clutter my method definitions with these.
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.