Original Post
fixed, thx for effort guys, updated code is below! Hey there guys.. I am using writeprocessmemory to call a dll function in another process. It does call the function, but the parameter doesn't work properly. It requires a HWND parameter. I have the same function with a string and that DOES work. I would like to have it working with a HWND parameter. Maybe someone succeeded in this or knows what I am doing wrong! Everything else is working properly (e.g. opening the process, as i already did a dll injection in the same function). Application (inside a bool function): DLL: Any suggestions are welcome! Thanks in advance. Edit: Eh it seems the forum doesn't like the cout arrows :b [Edited by - abort on August 15, 2008 3:08:57 PM]
HWND hWnd = FindWindow(NULL, "Application Window");
if (!hWnd) {
cout << "WriteProcessMemory error (" << GetLastError() << ").\n";
return false;
}
LPVOID lpWindow = VirtualAllocEx(hProcess, NULL, sizeof(HWND), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
if (!lpWindow) {
cout << "VirtualAllocEx error (" << GetLastError() << ").\n";
return false;
}
if (!WriteProcessMemory(hProcess, lpWindow, &hWnd, sizeof(HWND), NULL)) {
cout << "WriteProcessMemory error (" << GetLastError() << ").\n";
return false;
}
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lpFunctionAddress, lpWindow, 0, NULL); // Function address doesn't matter to you guys ;b
if (!hThread) {
cout << "CreateRemoteThread error (" << GetLastError() << ").\n";
return false;
}
extern "C" __declspec(dllexport) void Initialize(HWND* hWndptr) {
HWND hWnd = *hWndptr;
if (!IsWindow(hWnd)) MessageBox(NULL, "Invalid window", "test", MB_OK);
else MessageBox(NULL, "Valid window", "test", MB_OK);
}