Para
Para

Reputation: 858

Reading Desktop Icons via ListView (LVM_GETITEM) - Windows 7 problems

The following code works fine in Windows XP, and was working in Windows 7 at one point, but no longer works. I can't seem to figure out why unfortunately. Has anyone else had issues?

To be more specific, it finds all the icons, and their locations without issue. It's the iconname specifically that is returning /0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0.......

WriteProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),Marshal.SizeOf(typeof(LVITEM)), ref vNumberOfBytesRead);
SendMessage(vHandle, LVM_GETITEMW, j, vPointer.ToInt32());
ReadProcessMemory(vProcess, (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(LVITEM))), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vBuffer.Length, ref vNumberOfBytesRead);
string vText = Encoding.Unicode.GetString(vBuffer, 0, (int)vNumberOfBytesRead);
string IconName = Marshal.PtrToStringAnsi(vItem[0].pszText);

Neither vText nor IconName show anything :(

as for pszText, I have tried both of these:

vItem[0].pszText = (IntPtr)((int)vPointer + Marshal.SizeOf(typeof(LVITEM)));
vItem[0].pszText = Marshal.AllocHGlobal(512);

Just for reference:

private const int LVM_FIRST = 0x1000;
private const uint LVM_GETITEMW = LVM_FIRST + 75;

Full Code: (Ignore all the extra Console.WriteLines, I was debugging) http://pastebin.com/RXd2uwx3

Upvotes: 0

Views: 1664

Answers (1)

nyacom
nyacom

Reputation: 11

I have encountered same problem.

May be your code running under x64 version of windows7. In default C# build settings, IntPtr size regarded as 32bit int pointer. but ReadProcessMemory is 64bit int pointer.

You have to change VS's build option to [AnyCPU] to [x64], your code will be work well.

Upvotes: 1

Related Questions