从SysListView32中提取所有项目

时间:2012-11-13 19:47:07

标签: c++

我试图从SysListView32中提取所有项目,

这是代码:

#define WIN32_LEAN_AND_MEAN
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>

int main(void) {

 HWND hwnd=FindWindow(TEXT("Window"), TEXT("Cheat Engine 6.1"));
 HWND win=FindWindowEx(hwnd, NULL, TEXT("Window"), NULL);
 HWND listview=FindWindowEx(win, NULL, TEXT("SysListView32"), NULL);

    int count=(int)SendMessage(listview, LVM_GETITEMCOUNT, 0, 0);
    int i;

    LVITEM lvi, *_lvi;
    char item[512], subitem[512];
    char *_item, *_subitem;
    unsigned long pid;
    HANDLE process;

    GetWindowThreadProcessId(listview, &pid);
    process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, pid);

    _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);
    _item=(char*)VirtualAllocEx(process, NULL, 512, MEM_COMMIT, PAGE_READWRITE);
    _subitem=(char*)VirtualAllocEx(process, NULL, 512, 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(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);

        lvi.iSubItem=1;
        lvi.pszText=_subitem;
        WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL);
        SendMessage(listview, LVM_GETITEMTEXT, (WPARAM)i, (LPARAM)_lvi);

        ReadProcessMemory(process, _item, item, 512, NULL);
        ReadProcessMemory(process, _subitem, subitem, 512, NULL);

        printf("%s - %s\n", item, subitem);
    }

    VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);
    VirtualFreeEx(process, _item, 0, MEM_RELEASE);
    VirtualFreeEx(process, _subitem, 0, MEM_RELEASE);

    return 0;
}

错误:

第{p> cannot convert from 'char *' to 'LPWSTR'行:lvi.pszText=_item;

错误2:

第{p> IntelliSense: a value of type "char *" cannot be assigned to an entity of type "LPWSTR"行:lvi.pszText=_subitem;

我试过TEXT(_subitem),仍然无法正常工作。

1 个答案:

答案 0 :(得分:1)

使用TCHAR*wchar_t*代替char*。仅对字符串文字使用TEXT()