C++/CLI: Improved linkage to legacy Win32 DLLs?

R

_R

I've had to write a lot of code to interface C# to older Win32 DLLs.
Basically, an unmanaged C++ class talks directly to the Win32 DLL.
A managed C++ class encloses the unmanaged C++ class.
C# talks to the managed C++ class.

Lots of work. Is this simplified in C++/CLI? Any sample code
anywhere?
 
W

Willy Denoyette [MVP]

What do you mean with simplified? You still have to wrap the native class by
a managed class and delegate the method calls to their corresponding native
method implementations.

Willy.
 
R

_R

In the original version of my code I had two C++ wrappers--unmanaged
and managed. I did my best but it was tedious. From what little I've
read, I should be able to simplify to just one layer of C++ code,
right? In that declarations for managed vs unmanaged data are clear,
I can probably control that inline with handles vs pointers. Not sure
if the calls into the native Win32 DLL are more concise though. I'd
like to avoid using PInvoke, as some of the data types get obscure.
Is this made transparent in 2005beta2?
 
R

_R

In the original version of my code I had two C++ wrappers--unmanaged
and managed. I did my best but it was tedious. From what little I've
read, I should be able to simplify to just one layer of C++ code,
right? In that declarations for managed vs unmanaged data are clear,
I can probably control that inline with handles vs pointers. Not sure
if the calls into the native Win32 DLL are more concise though. I'd
like to avoid using PInvoke, as some of the data types get obscure.
Is this made transparent in 2005beta2?
 
R

_R

What do you mean with simplified? You still have to wrap the native class by
a managed class and delegate the method calls to their corresponding native
method implementations.

Willy.
[/QUOTE]

In the original version of my code I had two C++ wrappers--unmanaged
and managed. From what I've read, I should be able to simplify to just
one layer of C++ code,

PS: I could have stated that more clearly: I had two layers of C++
DLLs *in VS 2003*. I used an unmanaged wrapper to talk to the old
Win32 DLL. That wrapper collected functions into an organized class,
localized data, and generally imposed some structure.

A managed C++ DLL wrapped that unmanaged class so it could be called
easily from C#. Each DLL required different compile switches.

Q: Are there any new features in C++/CLI that would simplify this
process?
 
A

Arnaud Debaene

_R said:
PS: I could have stated that more clearly: I had two layers of C++
DLLs *in VS 2003*. I used an unmanaged wrapper to talk to the old
Win32 DLL. That wrapper collected functions into an organized class,
localized data, and generally imposed some structure.

A managed C++ DLL wrapped that unmanaged class so it could be called
easily from C#. Each DLL required different compile switches.

Q: Are there any new features in C++/CLI that would simplify this
process?

Well, you can certainly fold the 2 C++ DLLs (managed and unmanaged) into 1 :
just have the "organized class, localized data, and generally imposed some
structure" stuff be directly in the managed C++ DLL (MC++ and C++/CLI can
call directly on Win32).
Btw, you could have done the same thing in VS2003, although the syntaxic
clumsiness of MC++ would have made it cumbersome.

Arnaud
MVP - VC
 
R

_R

Well, you can certainly fold the 2 C++ DLLs (managed and unmanaged) into 1 :
just have the "organized class, localized data, and generally imposed some
structure" stuff be directly in the managed C++ DLL (MC++ and C++/CLI can
call directly on Win32).

Thanks, Arnaud. Do you happen to know of any code samples that would
illustrate the new syntax?
 

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