HANDLE hProcess = 0;
POINT *ptVitual = 0;
char *ptTitle = 0;
DWORD wndThreadID;
DWORD pID;
int i;
char title[256];
HWND main = ::FindWindow("Progman", NULL);
HWND defView = ::FindWindowEx(main, NULL, "SHELLDLL_DefView", NULL);
HWND list = ::FindWindowEx(defView, NULL, "SysListView32", NULL);
wndThreadID = ::GetWindowThreadProcessId(list, &pID);
hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, pID);
ptTitle = (char *)VirtualAllocEx(hProcess, NULL, 256, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
ptVitual = (POINT *)VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
CListCtrl mydesktop;
mydesktop.Attach(list);
int count = mydesktop.GetItemCount();
for(i = 0; i < count; i++) {
// read the item position (this is working)
mydesktop.GetItemPosition(x, ptVitual);
ReadProcessMemory(hProcess, ptVitual, &DesktopIcon.pt, sizeof(POINT), NULL);
// read the item text (not working)
mydesktop.GetItemText(x, 0, ptTitle, 255);
ReadProcessMemory(hProcess, ptTitle, &title, sizeof DesktopIcon.title, NULL);
// here there is a break to check the title variable content
}
mydesktop.Detach();
VirtualFreeEx(hProcess, ptTitle, 256, MEM_RELEASE);
VirtualFreeEx(hProcess, ptVitual, sizeof(POINT), MEM_RELEASE);
CloseHandle(hProcess);
fclose(file);
ASKER
typedef struct {
char title[256];
POINT pt;
RECT rect;
} DESKTOPICON;
void CDskSaverDlg::OnBnClickedSave()
{
CListCtrl mydesktop;
DESKTOPICON DesktopIcon;
HANDLE hProcess = 0;
POINT *ptPoint = 0;
char *ptTitle = 0;
DWORD wndThreadID;
DWORD pID;
int i, count;
HWND main = ::FindWindow("Progman", NULL);
HWND defView = ::FindWindowEx(main, NULL, "SHELLDLL_DefView", NULL);
HWND list = ::FindWindowEx(defView, NULL, "SysListView32", NULL);
wndThreadID = ::GetWindowThreadProcessId(main, &pID);
// Alloc memory to the process of SysListView32 window
hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, pID);
ptTitle = (char *)VirtualAllocEx(hProcess, NULL, sizeof(DesktopIcon.title), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
ptPoint = (POINT *)VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
// FILE *file;
// file = fopen("icone.bin", "w+");
// if(file == NULL) ::MessageBox(main, "Impossibile aprire il file.", "DLL", MB_OK);
// attach the list hwnd to the ListCtrl
mydesktop.Attach(list);
count = mydesktop.GetItemCount();
for(i = 0; i < count; i++) {
mydesktop.GetItemPosition(i, ptPoint);
ReadProcessMemory(hProcess, ptPoint, &DesktopIcon.pt, sizeof(POINT), NULL);
mydesktop.GetItemText(i, 0, ptTitle, sizeof(DesktopIcon.title)-1); // explorer crashes
ReadProcessMemory(hProcess, ptTitle, DesktopIcon.title, sizeof(DesktopIcon.title), NULL);
// fwrite(&DesktopIcon, sizeof(char), sizeof(DESKTOPICON), file);
}
mydesktop.Detach();
// Free memory
VirtualFreeEx(hProcess, ptTitle, sizeof(DesktopIcon.title), MEM_RELEASE);
VirtualFreeEx(hProcess, ptPoint, sizeof(POINT), MEM_RELEASE);
CloseHandle(hProcess);
// fclose(file);
// ::MessageBox(main, "Icone salvate.", "DZIconSave", MB_OK);
}
ASKER
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.
TRUSTED BY
try to pass 'title' instead of '&title' to 'ReadProcessMemory' - a 'char title[256]' already is a pointer to a 256 byte buffer, &title is a pointer to this pointer, not to the buffer ...
If this doesn't help please show how DesktopIcon is declared.
Hope that helps,
ZOPPO