internal static string FetchString(IntPtr handle)
{
if (handle == IntPtr.Zero)
return null;
string str;
int l = CFStringGetLength (handle);
IntPtr u = CFStringGetCharactersPtr (handle);
IntPtr buffer = IntPtr.Zero;
if (u == IntPtr.Zero){
CFRange r = new CFRange (0, l);
buffer = Marshal.AllocCoTaskMem (l * 2);
CFStringGetCharacters (handle, r, buffer);
u = buffer;
}
unsafe {
str = new string ((char *) u, 0, l);
}
if (buffer != IntPtr.Zero)
Marshal.FreeCoTaskMem (buffer);
return str;
}