multimodule assemblies and IJW/C++ Interop

B

Bern McCarty

I have a mixed DLL that "extends" an existing application and works just fine. It makes significant
use of IJW to interact with the native interfaces of the application that it is extending. I would
like to show that such application extensions can have parts authored in other .NET languages like
C#. So I set about rearranging my sample extension to become a multimodule assembly where one
..netmodule was authored in C# and another in MEC++ under VS 2003. And then I realized that I had no
idea how to really do this. My current mixed DLL uses a .def file and has some native .dll exports.
What do I do with them? Do I have to put the exported entry points into the module containing the
manifest (i.e. the assembly dll) ? Or can a native program do dynamic linking directly to a
mixed-mode .netmodule and have it work right?

Can anyone point me at an example that shows how to use create multi-language, multimodule
assemblies where some of the modules use IJW and have native exports?

Bern McCarty
Bentley Systems, Inc.
 
B

Bern McCarty

Some follow up information. I moved my native entry points to the manifest-containing-module. So I
have a 3 file assembly: 1 .netmodule for C#, 1 .netmodule (but with a .dll extension) which
contains nearly all of the logic that is written in C++, and the assembly file itself which contains
the native .DLL exports. Modules 2 and 3 work around the CLR 1.1 "Mixed DLL loading problem" in the
normal way.

When I try to load this extension, it crashes the process. The host program is doing a LoadLibrary
on my main assembly file. The debugger seems generally erratic and untrustworthy while I've been
trying to figure this out, but I eventually managed to get this stack trace on the crash. Does
Module::BuildClassForModule simply NOT work for Mixed modules?
EEClass::NotifyDebuggerAttach() + 0x11
EEClass::NotifyDebuggerLoad() + 0x12
Module::BuildClassForModule() + 0x5da1b
Module::SetContainer() + 0x2daaf
Assembly::AddModule() + 0x139
BaseDomain::SetAssemblyManifestModule() + 0x20
BaseDomain::LoadAssembly() + 0x339
ExecuteDLL() + 0x7eee8
__CorDllMain@12() + 0x1c
_LdrpCallInitRoutine@16() + 0x14
_LdrpRunInitializeRoutines@4() + 0x32f
_LdrpLoadDll@24() + 0x372
_LdrLoadDll@16() + 0x1c5
_LoadLibraryExW@12() + 0xc8
_LoadLibraryExA@12() + 0x1d
_LoadLibraryA@4() + 0x2f

Bern McCarty
Bentley Systems, Inc.
 
N

Nikola Dudar [MSFT]

Hi Bern,

The issue here is C++ .netmodule already has C++ libs pulled in. This can
result in a conflict with libs pulled in by the linker for C++ .obj. To
avoid this, use .netmodule only for VB and C# project and link all you C++
code as obj/libs. Try to change your build setup and if you still see
runtime errors, feel free to contact me directly. I will help you to resolve
those.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top