Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过ListView(LVM_GETITEM)读取桌面图标-Windows 7问题_C#_Winapi_User32_Lvm - Fatal编程技术网

C# 通过ListView(LVM_GETITEM)读取桌面图标-Windows 7问题

C# 通过ListView(LVM_GETITEM)读取桌面图标-Windows 7问题,c#,winapi,user32,lvm,C#,Winapi,User32,Lvm,下面的代码在WindowsXP中运行良好,曾经在Windows7中运行过,但现在不再运行。不幸的是,我似乎不明白为什么。还有其他人有问题吗 更具体地说,它会查找所有图标及其位置,而不会出现问题。具体来说,返回/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0的是iconname WriteProcessMemory(vProcess, vPointer, Marshal.UnsafeAddrOfPinnedArrayElement(vItem, 0),Marsh

下面的代码在WindowsXP中运行良好,曾经在Windows7中运行过,但现在不再运行。不幸的是,我似乎不明白为什么。还有其他人有问题吗

更具体地说,它会查找所有图标及其位置,而不会出现问题。具体来说,返回/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0/0的是iconname

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);
vText和IconName均未显示任何内容:(

至于pszText,我已经尝试了以下两种方法:

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

private const int LVM_FIRST = 0x1000;
private const uint LVM_GETITEMW = LVM_FIRST + 75;
完整代码:(忽略所有额外的Console.WriteLines,我正在调试)
我也遇到了同样的问题

可能是您的代码在x64版本的windows7下运行。 在默认C#构建设置中,IntPtr大小被视为32位int指针。 但ReadProcessMemory是64位int指针

您必须将VS的构建选项从[AnyCPU]更改为[x64],
你的代码会很好地工作。

嗯,如果不使用未记录的机制,正如你所观察到的,这些机制往往无法跨不同版本的Windows工作,为什么不使用呢?