Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* GetProcessPath(DWORD ProcessId)
- {
- char* ptr;
- char buffer[MAX_PATH];
- MessageBox(NULL, "ProcessPath() called", "Error", MB_ICONERROR);
- HANDLE hProcess;
- hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, ProcessId);
- if (GetModuleFileNameEx(hProcess, NULL, buffer, sizeof(buffer) / sizeof(char)))
- {
- ptr = buffer;
- }
- else {
- ptr = "\0";
- MessageBox(NULL, "Failed to get process path.", "Error", MB_ICONERROR);
- }
- return ptr;
- }
- DWORD WINAPI MainThread(PVOID p)
- {
- MessageBox(NULL, "Main thread called.", "Information", MB_ICONINFORMATION);
- char* path = GetProcessPath(GetProcessesByName("Spotify.exe"));
- MessageBox(NULL, path, "Information", MB_ICONINFORMATION);
- // Calling GetProcessPath() here crashes the slave process cause of using string without runtime library
- bool MAIN_THREAD = true;
- while (MAIN_THREAD)
- {
- if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)
- {
- MessageBox(NULL, "Main thread closed!", "Information", MB_ICONINFORMATION);
- MAIN_THREAD = false;
- }
- Sleep(1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement