471,073 Members | 1,279 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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 2078
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Fender Mussel | last post: by
1 post views Thread by Jesse McGrew | last post: by
reply views Thread by monika.saxena | last post: by
1 post views Thread by MC-Advantica | last post: by
9 posts views Thread by Amit Dedhia | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
reply views Thread by leo001 | last post: by

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.