Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Adams - 18 Nov 2006 16:52 GMT
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
Marcus Heege - 20 Nov 2006 07:12 GMT
> Hi,
> I try to use a C# Dialog in a legacy MFC application.
[quoted text clipped - 59 lines]
>
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.