Wrap old C DLL in new unmanaged C++ / Managed C++ DLL

B

_BNC

I have an old C DLL that I want to access via C#.

I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged
C++ class, which is in turn wrapped in a Managed C++ class. Both these
unmanaged C++ and managed C++ classes are compiled into a single assembly
(DLL) that is accessed by C#.

[C DLL] <--> [Unmanaged C++ / Managed C++] <--> [C# app]
old dll new C++ assembly app

I don't want to use standard Interop methods. I'm trying to do all the
direct access to the old C DLL with unmanaged C++. The data types in the
old C DLL are relatively complex, so I'm encapsulating the cluttered
legacy stuff in the new unmanaged C++ class.

IOW, I'll usually only be passing ints and a couple strings between the
unmanaged and managed sides.

In general, this approach works, but I'm getting occasional runtime errors
that I can't explain. Could someone post or refer me to a very simple
example that does this with even a single function? Say, take a function
from a stock Windows DLL and show a correct unmanaged C++ class
and managed C++ class that will wrap it correctly.

Thanks for any insights you can provide.
 
B

_BNC

I have an old C DLL that I want to access via C#.

I'm doing this via an outer DLL that wraps the old C DLL in an unmanaged
C++ class, which is in turn wrapped in a Managed C++ class. Both these
unmanaged C++ and managed C++ classes are compiled into a single assembly
(DLL) that is accessed by C#.

[C DLL] <--> [Unmanaged C++ / Managed C++] <--> [C# app]
old dll new C++ assembly app

I don't want to use standard Interop methods. I'm trying to do all the
^^^^^^^^^^
Oops... I meant I don't want to use PInvoke. I'm using the flat 'IJW'
model.
 
D

Derrick Coetzee [MSFT]

_BNC said:
I have an old C DLL that I want to access via C#.

[C DLL] <--> [Unmanaged C++ / Managed C++] <--> [C# app]
old dll new C++ assembly app

In general, this approach works, but I'm getting occasional runtime errors
that I can't explain.

You may be running into the dreaded Mixed DLL Loading problem:

http://msdn.microsoft.com/library/d...stechart/html/vcconMixedDLLLoadingProblem.asp

See if this helps. If not, try giving a minimal code example that causes
the error, or explaining some more detail of your setup.
 
B

_BNC

I'm getting some errors in an app that makes use of a mixed-mode DLL
for transitioning between .NET and an old native C DLL:

[C DLL] <--> [Unmanaged C++ / Managed C++] <--> [C# app]

I believe I got my initial info from an older Wrox book, so the problems
may have stemmed from there.

Is there a good source of info or examples of mixed Unmanaged/Managed
DLL's? Books, pointers to MSDN articles?
 

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