Name

Marshal

Synopsis

This class offers a collection of static methods for working with unmanaged memory and converting managed types to unmanaged types. Unless you are developing specialized code for marshaling types between managed and unmanaged code, you probably do not need to use any of these methods.

GetHRForException() converts a .NET exception to a COM HResult. If you are curious about the platform you are running on, you can find out the size of a character with the SystemDefaultCharSize field, which is 1 on an ANSI platform (Windows 9x/ME) and 2 on a Unicode platform (Windows NT, 2000, and XP).

Use the IsComObject() method to determine whether an object is actually an unmanaged COM object. The AddRef() method increments a COM object’s reference count.

public sealed class Marshal {
// Public Static Fields
   public static readonly field int SystemDefaultCharSize;       // =2
   public static readonly field int SystemMaxDBCSCharSize;       // =1
                  // Public Static Methods
   public static method int AddRef(IntPtr pUnk);  
   public static method IntPtr AllocCoTaskMem(int cb);  
   public static method IntPtr AllocHGlobal(int cb);  
   public static method IntPtr AllocHGlobal(IntPtr cb);  
   public static method object BindToMoniker(
        string monikerName);  
   public static method void ChangeWrapperHandleStrength(
        object otp, bool fIsWeak);  
   public static method void Copy(byte[] source, 
        int startIndex, IntPtr destination, int length);  
   public static method void Copy(char[] source, 
        int startIndex, IntPtr destination, int ...

Get C# in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.