获取x86和x64上的桌面图标列表? [英] Getting a list of Desktop Icons on x86 and x64?
问题描述
大家好,
我正在尝试获取桌面图标/位置的列表,我对文章中的一些代码进行了一些修改,目前它在x86 Windows XP/Vista/7上可以正常运行,但是在x64操作系统上,返回的值是空的. hWnd包含桌面列表视图:
I'm trying to get a list of desktop icons/positions, I've slightly modified some code from an article and currently it works perfectly on x86 Windows XP/Vista/7, but on x64 operating systems the value returned is empty. hWnd contains the desktop listview:
int count=(int)SendMessage(hWnd, LVM_GETITEMCOUNT, 0, 0);
int i;
LVITEM lvi, *_lvi;
char item[512];
char *_item;
unsigned long pid;
HANDLE process;
GetWindowThreadProcessId(hWnd, &pid);
process=OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, pid);
_lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
_item=(CHAR*)VirtualAllocEx(process, NULL, 512, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
lvi.cchTextMax=512;
for(i = 0; i < count; i++)
{
lvi.iSubItem=0;
lvi.pszText=_item;
WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);
ReadProcessMemory(process, _item, item, 512, NULL);
printf("%s\n", item);
}
VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
VirtualFreeEx(process, _item, 0, MEM_RELEASE);
我四处搜寻,很多人似乎都遇到了同样的问题,但没有任何解决方案.有人建议这是因为x64的LVITEM长度不同...但是我不知道该怎么办.理想情况下,我需要一个可以在x86或更高版本下运行的可执行文件 x64并可以获取图标列表(我不想拥有单独的x86/x64可执行文件).
I've searched around and lots of people seem to have the same problem, but without any solutions. Someone suggested it's because x64 has a different LVITEM length... but I don't know what to do about that. Ideally I need one executable that runs in x86 or x64 and can get the list of icons (I don't want to have separate x86/x64 executables).
提前感谢您的帮助!
推荐答案
如果您不想拥有单独的x86/x64可执行文件,那么您选择了错误的选项使用的语言.如果您是从纯.Net应用程序(C#或带有/clr:pure的C ++/CLI)中使用P/Invoke,则可以摆脱一个可执行文件,但是很不走运 使用C ++.
If you don't want to have separate x86/x64 executables, then you chose the wrong language to work with. You could get away with a single executable if you used P/Invoke from a pure .Net application (C# or C++/CLI with /clr:pure), but you're out of luck with C++.
这篇关于获取x86和x64上的桌面图标列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!