By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,165 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,165 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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.