C++/CLI: Improved linkage to legacy Win32 DLLs?
6 answers - 319 bytes -

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?
No.1 | | 693 bytes |
| 
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@noemail.org> wrote in message
news:l54bj15t32jkicaoe68vrfreti3fbqr9m9@
4ax.com...
> 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?
>
No.2 | | 996 bytes |
| 
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?
On Sat, 24 Sep 2005 20:31:06 +0200, "Willy Denoyette [MVP]"
<willy.denoyette@telenet.be> wrote:
>What do you mean with simplified? You still have to wrap the native class b
y
>a managed class and delegate the method calls to their corresponding native
>method implementations.
>Willy.
>"_R" <_R@noemail.org> wrote in message
> news:l54bj15t32jkicaoe68vrfreti3fbqr9m9@
4ax.com...
No.3 | | 781 bytes |
| 
On Sat, 24 Sep 2005 20:28:50 -0400, _R <_R@noemail.org> wrote:
>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?
>On Sat, 24 Sep 2005 20:31:06 +0200, "Willy Denoyette [MVP]"
><willy.denoyette@telenet.be> wrote:
>
No.4 | | 920 bytes |
| 
>On Sat, 24 Sep 2005 20:31:06 +0200, "Willy Denoyette [MVP]"
><willy.denoyette@telenet.be> wrote:
>
On Sat, 24 Sep 2005 20:28:50 -0400, _R <_R@noemail.org> wrote:
> 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?
No.5 | | 1072 bytes |
| 
_R wrote:
> On Sat, 24 Sep 2005 20:28:50 -0400, _R <_R@noemail.org> wrote:
>
> 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
No.6 | | 540 bytes |
| 
On Sun, 25 Sep 2005 11:48:35 +0200, "Arnaud Debaene"
<adebaene@club-internet.fr> wrote:
>_R wrote:
>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?