public static T AEGetNthPtr <T> (ref AEDesc descList, int index, CarbonEventParameterType desiredType) where T : struct { int len = Marshal.SizeOf(typeof(T)); IntPtr bufferPtr = Marshal.AllocHGlobal(len); try { CheckReturn((int)AEGetNthPtr(ref descList, index, desiredType, 0, 0, bufferPtr, len, 0)); T val = (T)Marshal.PtrToStructure(bufferPtr, typeof(T)); return(val); } finally{ Marshal.FreeHGlobal(bufferPtr); } }
public static List <string> GetUrlListFromEventRef(IntPtr eventRef) { AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList); long count = AECountItems(ref list); var files = new List <string> (); for (int i = 1; i <= count; i++) { string url = GetStringFromAEPtr(ref list, i); if (!string.IsNullOrEmpty(url)) { files.Add(url); } } Carbon.CheckReturn(Carbon.AEDisposeDesc(ref list)); return(files); }
public static List <string> GetFileListFromEventRef(IntPtr eventRef) { AEDesc list = GetEventParameter <AEDesc> (eventRef, CarbonEventParameterName.DirectObject, CarbonEventParameterType.AEList); long count = AECountItems(ref list); var files = new List <string> (); for (int i = 1; i <= count; i++) { FSRef fsRef = AEGetNthPtr <FSRef> (ref list, i, CarbonEventParameterType.FSRef); string file = FSRefToPath(ref fsRef); if (!string.IsNullOrEmpty(file)) { files.Add(file); } } CheckReturn(AEDisposeDesc(ref list)); return(files); }
//FIXME: this might not work in some encodings. need to test more. static string GetStringFromAEPtr(ref AEDesc descList, int index) { int size; CarbonEventParameterType type = CarbonEventParameterType.UnicodeText; if (AESizeOfNthItem(ref descList, index, ref type, out size) == AEDescStatus.Ok) { IntPtr buffer = Marshal.AllocHGlobal(size); try { if (AEGetNthPtr(ref descList, index, type, 0, 0, buffer, size, 0) == AEDescStatus.Ok) { return(Marshal.PtrToStringAuto(buffer, size)); } } finally { Marshal.FreeHGlobal(buffer); } } return(null); }
public static extern AEDescStatus AESizeOfNthItem(ref AEDesc descList, int index, ref CarbonEventParameterType type, out int size);
public static extern int AEDisposeDesc(ref AEDesc desc);
static extern AEDescStatus AEGetNthPtr(ref AEDesc descList, int index, CarbonEventParameterType desiredType, uint keyword, uint zero, out IntPtr outPtr, int bufferSize, int zero2);
static extern AEDescStatus AEGetNthPtr(ref AEDesc descList, int index, CarbonEventParameterType desiredType, uint keyword, out CarbonEventParameterType actualType, IntPtr buffer, int bufferSize, out int actualSize);
static extern int AECountItems(ref AEDesc descList, out int count); //return an OSErr
static extern NavStatus NavCustomControl(IntPtr dialog, NavCustomControlMessage selector, ref AEDesc parm);