2012-11-13 158 views
0

我試圖從SysListView32提取的所有項目,提取的所有項目從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; 
} 

錯誤:

cannot convert from 'char *' to 'LPWSTR'在行:lvi.pszText=_item;

錯誤2 :

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

我試過TEXT(_subitem),仍然無法正常工作。

回答

1

使用TCHAR*wchar_t*而不是char*。僅對字符串文字使用TEXT()

+0

謝謝,(wchar_t *)有效。 – famf