How to put wstring title in the LPCWSTR findwindow? Or how do I convert wstring title?
#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
#include <tlhelp32.h>
#include <sstream>
#include <stdlib.h>
#include <atlstr.h>
#include <locale>
#include <codecvt>
using namespace std;
DWORD ProcessId = 30850.352;
LPCWSTR pid;
LPWSTR widestr;
HWND hwnd;
bool isNotepad(const PROCESSENTRY32W& entry) {
return std::wstring(entry.szExeFile) == L"simplewrapper.exe";
}
BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {
const auto& pids = *reinterpret_cast<std::vector<dword>*>(lParam);
std::string winId2;
DWORD winId;
GetWindowThreadProcessId(hwnd, &winId);
//Converting DWORD to string
std::string DwordToString(std::string winId2, std::string cur_str, DWORD winId);
{
std::string winId2 = std::to_string(long long(winId));
}
for (DWORD pid : pids) {
if (winId == pid) {
std::wstring title(GetWindowTextLength(hwnd) + 1, L'\0'); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GetWindowTextW(hwnd, &title[0], title.size()); //note: C++11 only
std::cout << "Found window:\n";
std::cout << "Process ID: " << pid << '\n';
std::wcout << "Title: " << title << "\n\n";
return 0;
}
}
return TRUE;
}
int main(int argc, char** argv) {
std::vector<dword> pids;
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32W entry;
entry.dwSize = sizeof entry;
if (!Process32FirstW(snap, &entry)) {
return 0;
}
do {
if (isNotepad(entry)) {
pids.emplace_back(entry.th32ProcessID);
}
} while (Process32NextW(snap, &entry));
EnumWindows(enumWindowsProc, reinterpret_cast<lparam>(&pids));
int lpBuffer = 30000.000;
hwnd = FindWindow(0, /*TEXT("MSCTFIME UI"*/ title /*)*/);<<<<<<<<<<<<<<<<<<<<<
if (hwnd == NULL) {
cout << "Cannot find window." << endl;
}
else {
cout << "Found window." << endl;
GetWindowThreadProcessId(hwnd, &ProcessId);
//HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId);
}
if (HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId)) {
cout << "Opened Process." << endl;
int MemoryHack = WriteProcessMemory(hProcess, (LPVOID)0x70EB2190, &lpBuffer, sizeof(lpBuffer), NULL);
int MemoryHack2 = WriteProcessMemory(hProcess, (LPVOID)0x70EB2190, &lpBuffer, sizeof(lpBuffer), NULL);
if (!MemoryHack) {
cout << "Unable to write MemoryHack to memory" << endl;
}
else {
cout << "Failed to OpenProcess." << endl;
}
CloseHandle(hProcess);
}
else {
}
return 0;
}
What I have tried:
<pre>#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
#include <tlhelp32.h>
#include <sstream>
#include <stdlib.h>
#include <atlstr.h>
#include <locale>
#include <codecvt>
using namespace std;
DWORD ProcessId = 30850.352;
LPCWSTR pid;
LPWSTR widestr;
HWND hwnd;
bool isNotepad(const PROCESSENTRY32W& entry) {
return std::wstring(entry.szExeFile) == L"simplewrapper.exe";
}
BOOL CALLBACK enumWindowsProc(HWND hwnd, LPARAM lParam) {
const auto& pids = *reinterpret_cast<std::vector<dword>*>(lParam);
std::string winId2;
DWORD winId;
GetWindowThreadProcessId(hwnd, &winId);
std::string DwordToString(std::string winId2, std::string cur_str, DWORD winId);
{
std::string winId2 = std::to_string(long long(winId));
}
for (DWORD pid : pids) {
if (winId == pid) {
std::wstring title(GetWindowTextLength(hwnd) + 1, L'\0'); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GetWindowTextW(hwnd, &title[0], title.size());
std::cout << "Found window:\n";
std::cout << "Process ID: " << pid << '\n';
std::wcout << "Title: " << title << "\n\n";
return 0;
}
}
return TRUE;
}
int main(int argc, char** argv) {
std::vector<dword> pids;
HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32W entry;
entry.dwSize = sizeof entry;
if (!Process32FirstW(snap, &entry)) {
return 0;
}
do {
if (isNotepad(entry)) {
pids.emplace_back(entry.th32ProcessID);
}
} while (Process32NextW(snap, &entry));
EnumWindows(enumWindowsProc, reinterpret_cast<lparam>(&pids));
int lpBuffer = 30000.000;
hwnd = FindWindow(0, title );<<<<<<<<<<<<<<<<<<<<<
if (hwnd == NULL) {
cout << "Cannot find window." << endl;
}
else {
cout << "Found window." << endl;
GetWindowThreadProcessId(hwnd, &ProcessId);
}
if (HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessId)) {
cout << "Opened Process." << endl;
int MemoryHack = WriteProcessMemory(hProcess, (LPVOID)0x70EB2190, &lpBuffer, sizeof(lpBuffer), NULL);
int MemoryHack2 = WriteProcessMemory(hProcess, (LPVOID)0x70EB2190, &lpBuffer, sizeof(lpBuffer), NULL);
if (!MemoryHack) {
cout << "Unable to write MemoryHack to memory" << endl;
}
else {
cout << "Failed to OpenProcess." << endl;
}
CloseHandle(hProcess);
}
else {
}
return 0;
}