471,066 Members | 1,258 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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

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.
Nov 17 '05 #1
3 1862
On Sun, 09 Jan 2005 21:52:43 -0500, _BNC <_B**@nospam.com> wrote:
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.

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.


Nov 17 '05 #2
_BNC wrote:
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/de...ingProblem.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.
--
Derrick Coetzee, Microsoft Speech Server developer
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included code samples are subject to the terms
specified at http://www.microsoft.com/info/cpyright.htm
Nov 17 '05 #3
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?

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Chris Kiechel | last post: by
4 posts views Thread by Rachel Suddeth | last post: by
1 post views Thread by Sparhawk | last post: by
2 posts views Thread by =?Utf-8?B?Y2hyaXNiZW4=?= | last post: by
2 posts views Thread by Jon Slaughter | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.