
Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/
> So for your example it looks like the following:
>
> <code>
> #pragma unmanaged
Hey, wait a minute... this "#pragma unmanaged" is specific for C++/CLI
right...? I only have VS 2003 with Managed Extensions for C++... or is this
valid in VS 2003 too?
> class MyClass
> {
[quoted text clipped - 5 lines]
> };
> #pragma managed
Ok, now the definition of MyClass is in the same file as my wrapper but the
fact is that the unmanaged API functions reside in a DLL (or a .lib). How
can I get access to them?
Do I need to derive from IDisposable? What happens if I don't?
Thx!!!
> public __gc class MyClassWrapper : public IDisposable
> {
[quoted text clipped - 57 lines]
> };
> </code>
Jochen Kalmbach [MVP] - 24 May 2005 10:43 GMT
Hi Tommy!
>><code>
>>#pragma unmanaged
>
> Hey, wait a minute... this "#pragma unmanaged" is specific for C++/CLI
> right...? I only have VS 2003 with Managed Extensions for C++... or is this
> valid in VS 2003 too?
It is also valid in VC2003.
By the way: You do not need to set this pragma! I just wanted to show
that this class really can be an unmanaged or native class!
> Ok, now the definition of MyClass is in the same file as my wrapper but the
> fact is that the unmanaged API functions reside in a DLL (or a .lib). How
> can I get access to them?
Äh... whyt should be the problem?
Include the h-File, and add the LIB to your linker settings.
> Do I need to derive from IDisposable? What happens if I don't?
An managed class has a non-deterministic life-time!
If you have references to native resources, then you *should* implement
the "IDisposable" pattern.
There are only two other ways to overcome this:
1. It does not matter if the native-resource will be freed from a
different thread during finalization
2. You do not allocate a native-resource in the cinstructor; instead you
allocate it on every method and destroy it before you leave the method.

Signature
Greetings
Jochen
My blog about Win32 and .NET
http://blog.kalmbachnet.de/