473,508 Members | 4,712 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\system32\mscoree.dll' geladen, Keine Symbole
geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\mfc71d.dll' geladen, Symbole geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\user32.dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\system32\shlwapi.dll' geladen, Keine Symbole
geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\rpcrt4.dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\system32\msvcrt.dll' geladen, Keine Symbole
geladen.

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

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

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

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

Eine Ausnahme (erste Chance) bei 0x7c928fea in SeaMain.exe: 0xC0000005:
Zugriffsverletzung-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
CorBindToRuntimeEx

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 2237
"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\system32\mscoree.dll' geladen, Keine Symbole
geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\mfc71d.dll' geladen, Symbole geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\user32.dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\system32\shlwapi.dll' geladen, Keine Symbole
geladen.

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

'SeaMain.exe': 'E:\WINDOWS\system32\rpcrt4.dll' geladen, Keine Symbole
geladen.

'SeaMain.exe': 'E:\WINDOWS\system32\msvcrt.dll' geladen, Keine Symbole
geladen.

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

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

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

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

Eine Ausnahme (erste Chance) bei 0x7c928fea in SeaMain.exe: 0xC0000005:
Zugriffsverletzung-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
CorBindToRuntimeEx

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 CorBindToRuntimeEx 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 ShowCSharpDialog()
{
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
11727
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...
1
1329
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...
1
2881
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...
1
2581
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,...
0
1748
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....
1
3414
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...
9
3100
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...
3
4684
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...
7
2663
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...
0
7228
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,...
0
7332
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,...
1
7058
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
4715
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...
0
3206
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...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
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 ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
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...

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.