Visual Studio 2010!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.
ADVERTISEMENT
ADVERTISEMENT

 

DevSource.com: Your Source for Visual Studio on Facebook
ADVERTISEMENT
Cabinet Files Revisited
By Jim Mischel

Rate This Article: Add This Article To:

Cabinet Files Revisited - ' Moving to '
( Page 3 of 4 )

.NET 2.0">

Moving to .NET 2.0

Version 2.0 of the .NET Framework introduced the UnmanagedFunctionPointerAttribute, which controls the marshaling behavior of a delegate signature passed as an unmanaged function pointer to or from unmanaged code.

In particular, UnmanagedFunctionPointerAttribute lets you specify the calling convention to be used by a managed callback. It has the same fields as the DllImportAttribute used to specify the marshaling behavior when calling unmanaged functions that are exported from a DLL.

To create a managed callback that supports the Cdecl calling convention, you apply the UnmanagedFunctionPointerAttribute to the delegate type declaration, like this:

[C#]
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr FdiMemAllocDelegate(int numBytes);

[Visual Basic]
<UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
Public Delegate Function FdiMemAllocDelegate(numBytes As Integer) as IntPtr

The existence of UnmanagedFunctionPointerAttribute in .NET 2.0 eliminated the need for the custom CallConvCdeclAttribute class and the messy post-processing of the compiled code that had to do to access the Cabinet SDK from .NET 1.1. Converting CabDotNet to .NET 2.0 consisted mostly of replacing all of the CallConvCdeclAttribute instances in cabsdk.cs to UnmanagedFunctionAttribute(CallingConvention.Cdecl) — an easy search and replace operation.

Other Changes

The Design Guidelines for Developing Class Libraries recommends that namespaces take the form:

<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]

In an effort to meet that guideline, I changed the CabDotNet namespace to Mischel.CabDotNet.

The need to post-process the compiled code in the .NET 1.1 version forced me to move the CabWrapper namespace, which contains the CabCompressor and CabDecompressor classes, from the CabDotNet project into a separate project. Doing so meant that any program that wanted to use CabWrapper had to reference two separate assemblies. That always disappointed me, because I like simple installs; the fewer assemblies I have to install, the easier it is to debug odd problems. The .NET 2.0 version of CabDotNet moves the CabCompressor and CabDecompressor classes into the Mischel.CabDotNet namespace and eliminates the CabWrapper namespace.

In my original code, I failed to mark as virtual some of the functions in CabCompressor and CabDecompressor that should be so marked. I fixed those and a few other minor errors in the class implementations.

Finally, I added XML documentation comments to all of the classes in the Mischel.CabDotNet namespace. This should make working with the code a bit easier.



 
 
>>> More Using Microsoft Visual Studio Articles          >>> More By Jim Mischel