private static string GetIconTitle(IntPtr desktopHandle, IntPtr desktopProcess, int index) { var vPointer = NM.VirtualAllocEx(desktopProcess, IntPtr.Zero, (IntPtr)2048, NM.MEM_RESERVE | NM.MEM_COMMIT, NM.PAGE_READWRITE); try { var vBuffer = new byte[256]; var vNumberOfBytesRead = new IntPtr(0); var vItem = new NativeMethods.LVITEM[1]; vItem[0].mask = NM.LVIF_TEXT; vItem[0].iItem = index; vItem[0].iSubItem = 0; vItem[0].cchTextMax = vBuffer.Length; vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVITEM))); NM.WriteProcessMemory(desktopProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), (IntPtr)Marshal.SizeOf(typeof(NativeMethods.LVITEM)), ref vNumberOfBytesRead); if (NM.SendMessage(desktopHandle, NM.LVM_GETITEMW, index, vPointer.ToInt32()) == 0) { return(string.Empty); } NM.ReadProcessMemory(desktopProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NativeMethods.LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), (IntPtr)vBuffer.Length, ref vNumberOfBytesRead); return(Encoding.Unicode.GetString(vBuffer, 0, (int)vNumberOfBytesRead)); } finally { NM.VirtualFreeEx(desktopProcess, vPointer, (IntPtr)0, NM.MEM_RELEASE); } }
static string GetIconTitle(IntPtr desktopHandle, IntPtr desktopProcess, int index) { var vPointer = NM.VirtualAllocEx(desktopProcess, IntPtr.Zero, (IntPtr)2048, NM.MEM_RESERVE | NM.MEM_COMMIT, NM.PAGE_READWRITE); try { var vBuffer = new byte[256]; var vNumberOfBytesRead = new IntPtr(0); var vItem = new NM.LVITEM[1]; vItem[0].mask = NM.LVIF_TEXT; vItem[0].iItem = index; vItem[0].iSubItem = 0; vItem[0].cchTextMax = vBuffer.Length; vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NM.LVITEM))); NM.WriteProcessMemory(desktopProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0), (IntPtr)Marshal.SizeOf(typeof(NM.LVITEM)), ref vNumberOfBytesRead); if (NM.SendMessage(desktopHandle, NM.LVM_GETITEMW, index, vPointer.ToInt32()) == 0) return string.Empty; NM.ReadProcessMemory(desktopProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(NM.LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), (IntPtr)vBuffer.Length, ref vNumberOfBytesRead); return Encoding.Unicode.GetString(vBuffer, 0, (int)vNumberOfBytesRead); } finally { NM.VirtualFreeEx(desktopProcess, vPointer, (IntPtr)0, NM.MEM_RELEASE); } }