473,714 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling managed c++ from an unmanaged mfc application (VC 7.1)

Hi,
I try to use a C# Dialog in a legacy MFC application.
The problem seems to boil down to the following:
from an unmanaged console application I can call any function of the managed
bridge - if I try to do the same from my mfc application the application
won't start
'SeaMain.exe': 'E:\WINDOWS\sys tem32\mscoree.d ll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcr71d. dll' geladen, Symbole geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\mfc71d.dl l' geladen, Symbole geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\gdi32.dll ' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\user32.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\shlwapi.d ll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\advapi32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\rpcrt4.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcrt.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\comctl32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\oleaut32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\ole32.dll ' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcp71d. dll' geladen, Symbole geladen.

Eine Ausnahme (erste Chance) bei 0x7c928fea in SeaMain.exe: 0xC0000005:
Zugriffsverletz ung-Schreibposition 0x00000010.

Eine Ausnahme (erste Chance) bei 0x7c974ed1 in SeaMain.exe: 0xC0000005:
Access violation.

From what I have found in the net I conclude that calling managed code from
unmanaged code in an MFC application requires hosting the CLR somehow using
CorBindToRuntim eEx

Moreover it looks as if I have to use COM interop in that case.

If these conclusion are wrong, (which I silently hope) how can I call into
managed dll from an unmanaged MFC application?

Thanks in advance,

Arne
Nov 18 '06 #1
1 2253
"Arne Adams" <ar********@t-online.dewrote in message
news:ej******** *****@news.t-online.com...
Hi,
I try to use a C# Dialog in a legacy MFC application.
The problem seems to boil down to the following:
from an unmanaged console application I can call any function of the
managed bridge - if I try to do the same from my mfc application the
application won't start
'SeaMain.exe': 'E:\WINDOWS\sys tem32\mscoree.d ll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcr71d. dll' geladen, Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\mfc71d.dl l' geladen, Symbole geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\gdi32.dll ' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\user32.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\shlwapi.d ll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\advapi32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\rpcrt4.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcrt.dl l' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\comctl32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\oleaut32. dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\ole32.dll ' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\sys tem32\msvcp71d. dll' geladen, Symbole
geladen.

Eine Ausnahme (erste Chance) bei 0x7c928fea in SeaMain.exe: 0xC0000005:
Zugriffsverletz ung-Schreibposition 0x00000010.

Eine Ausnahme (erste Chance) bei 0x7c974ed1 in SeaMain.exe: 0xC0000005:
Access violation.

From what I have found in the net I conclude that calling managed code
from unmanaged code in an MFC application requires hosting the CLR somehow
using
CorBindToRuntim eEx

Moreover it looks as if I have to use COM interop in that case.

If these conclusion are wrong, (which I silently hope) how can I call into
managed dll from an unmanaged MFC application?

Thanks in advance,

Arne
1) There is no need to call CorBindToRuntim eEx manually.
2) Choose the /Zi compiler switch for your whole project
3) Add a new file to your project.
4) Modify the following property switches for the file
set /clr (mixed code compilation model)
set /EHa (async exceptions)
don't set /Gm, /RTC1 (non minimal rebuild, no runtime checks)
don't use /Yu (precompiled header)
5) In your file write something like this
#using "MyCSharpUIDLL. dll"

void ShowCSharpDialo g()
{
MyCSharpDialog dlg = __gc new MyCSharpDialog( );
dlg.ShowDialog( );
}
6) Call that functin from your code

HTH

Marcus Heege
Nov 20 '06 #2

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

Similar topics

15
11785
by: Bryan | last post by:
I have a multi-threaded C# console application that uses WMI (System.Management namespace) to make RPC calls to several servers (600+ ) and returns ScheduledJobs. The section of my code that performs the query is contained in a delegate function that I execute via a second thread. On 1 or 2 of the 600+ servers the query hangs. I've tried to use Thread.Join() coupled with a Thread.Abort() but this does not kill the thread. Based on...
1
1336
by: Fender Mussel | last post by:
Hi, We are in a situation where we have a Win32 application which is currently deployed to about 15000 desktop machines and want to rewrite the back end (business logic) in a modern language. At the moment there is no change for changing the front end (GUI) because it's far to complex to rewrite it now. Thus, we are currently evaluating several alternatives for programming languages and one very favourite candidate is C#.
1
2907
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code written in C#. When the app calls my unmanaged functions, they work fine. But as soon as my unmanaged functions call managed functions (in the same source file!), the app reports an "unknown exception" error.
1
2603
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender, System::EventArgs * e) { MyDLLInit(MyAppDisplayFunction); }
0
1760
by: monika.saxena | last post by:
Hi all, In one of my projects which is a web based application in asp.net, a third party tool - "Frontline Solver DLL" (It is an unmanaged DLL and ..NET is calling it using the PInvoke) is used. This DLL is used for solving and optimizing some non linear problems. Problem : The problem I am facing is as the solver runs and does the
1
3435
by: MC-Advantica | last post by:
Does anyone have a simple "Hello World" like application that demonstrates unmanaged C++ calling managed C++ developed in VS2005? I'm confused by many posts as they discuss managed extensions from VS2003, and related techniques. I have found managed to unmanaged technique very easy in VS2005, but have not been able to build anything with unmanaged to managed calls. I have legacy (unmanaged C++) that would like to leverage the .NET...
9
3121
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
3
4708
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC application. Furthermore, I use a pointer to an unmanaged function to jump back into the managed dll. The managed part is basically a remoting enhancement which asynchronly
7
2686
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
0
8712
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9316
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
9182
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
7955
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
6638
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
5959
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();...
1
3160
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
2
2526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2113
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.