I have to access some C# GUI code from a legacy (VC6.0) MFC GUI app. My
1st approach was to bridge the unmanaged/managed world with a COM-Callable
Wrapper (CCW) object. That worked great. Now management says we don't want
to require Admin privilges to install the code (the CCW requires REGASM to
create the Registry entries for the COM calls). So I am trying to figure
out how to create a managed C++ DLL that can accept calls from the legacy
MFC 6.0 app and create the .NET objects in there.

I started with a hello world type of managed C++ DLL and I proved that
from a simple VC6.0 console app, I can at least call into the managed C++
DLL and call functions and create unmanaged classes. This is right out of
Grimes and works fine.

HOWEVER, if I build any app (VC6.0 or VC7.0) that uses MFC, the app
crashes and burns before WinMain is even called. I get access violations
as I see the various .NET-related DLLs loading. Any ideas on how to
configure the project so that it works??? In my case, it is not IJW, it is
IJDW.

Here are some details:

'Tester.exe': Loaded 'F:\NET\MgdTest\Tester\Debug\Tester.exe', Symbols
loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\ntdll.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\kernel32.dll', No symbols loaded.
'Tester.exe': Loaded 'F:\NET\MgdTest\Tester\Debug\MgdCppTest.dll', Symbols
loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\mscoree.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\advapi32.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\rpcrt4.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\msvcr71.dll', Symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\mfc71d.dll', Symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\msvcr71d.dll', Symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\gdi32.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\user32.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\SHLWAPI.DLL', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\msvcrt.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\oleaut32.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\ole32.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\msvcp71d.dll', Symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\Microsoft.NET\Framework\v1.1.4322
\mscorwks.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\Microsoft.NET\Framework\v1.1.4322
\fusion.dll', No symbols loaded.
'Tester.exe': Loaded 'C:\WINNT\system32\shell32.dll', No symbols loaded.
First-chance exception at 0x77f57bd2 in Tester.exe: 0xC0000005: Access
violation reading location 0x00000010.
'Tester.exe': Unloaded 'C:\WINNT\Microsoft.NET\Framework\v1.1.4322
\mscorwks.dll'
'Tester.exe': Unloaded 'C:\WINNT\system32\shell32.dll'
'Tester.exe': Unloaded 'C:\WINNT\Microsoft.NET\Framework\v1.1.4322
\fusion.dll'
'Tester.exe': Loaded 'C:\WINNT\system32\mui\0409\mscoreer.dll', No symbols
loaded.
First-chance exception at 0x00000000 in Tester.exe: 0xC0000005: Access
violation reading location 0x00000000.
First-chance exception at 0x77f966bc in Tester.exe: 0xC0000005: Access
violation.
Unhandled exception at 0x77f966bc in Tester.exe: 0xC0000005: Access
violation.
The program '[7808] Tester.exe: Native' has exited with code 128 (0x80).

The managed C++ project was created using Visual Studio .NET 2003 using
the Visual C++ Class Library (.NET) Project template. I pretty much built
the project with no mods. The .h file looks like this:

#ifdef MGDCPPTEST_EXPORTS
#define MGDCPPTEST_API __declspec(dllexport)
#else
#define MGDCPPTEST_API __declspec(dllimport)
#endif

// This class is exported from the UmgdCppTest.dll
class MGDCPPTEST_API CMgdCppTest {
public:
 CMgdCppTest(void);
 // TODO: add your methods here.

public:
 int   CallMe(int n);

};

MGDCPPTEST_API int CallMe2(int n);

I then went and created a client app using the C++ Win32 Console App
project template and added MFC support to this. I include the .h file and
link with the .lib file and like I said, it crashes before I get to _tmain
().

I get same results with a simple VC6.0 MFC GUI app.

Any thoughts on the matter?

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to