I am trying to print and save the module names of a process.
But when printing the char array I get something that looks like an address.
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
int main() {
MODULEENTRY32 me32;
HWND hwnd = FindWindow(0, L"Window Name");
DWORD dwPID;
GetWindowThreadProcessId(hwnd, &dwPID);
HANDLE hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
me32.dwSize = sizeof(MODULEENTRY32);
Module32First(hModuleSnap, &me32);
std::cout << me32.szModule << std::endl;
do
{
std::cout << me32.szModule << std::endl; // important line
} while (Module32Next(hModuleSnap, &me32));
return 0;
}
The output of this in my case was 00AFF53C
for every module.
me32.szModule
holds the name of the module as a char array.
Microsoft used the following in their example to convert and print the module name:
_tprintf( TEXT("\n\n MODULE NAME: %s"), me32.szModule );
But I think you can only use this to print the string.
So how do I convert and save the string in me32
?