static string CFStringGetString (IntPtr handle) { if (handle == IntPtr.Zero) return null; string str; int length = CFStringGetLength (handle); IntPtr unicode = CFStringGetCharactersPtr (handle); IntPtr buffer = IntPtr.Zero; if (unicode == IntPtr.Zero) { CFRange range = new CFRange (0, length); buffer = Marshal.AllocCoTaskMem (length * 2); CFStringGetCharacters (handle, range, buffer); unicode = buffer; } unsafe { str = new string ((char *) unicode, 0, length); } if (buffer != IntPtr.Zero) Marshal.FreeCoTaskMem (buffer); return str; }
extern static void CFDataGetBytes (IntPtr handle, CFRange range, IntPtr buffer);
extern static void CFDataGetBytes(IntPtr handle, CFRange range, IntPtr buffer);
extern static IntPtr CFStringGetCharacters (IntPtr handle, CFRange range, IntPtr buffer);