I was having trouble getting a substring using
strstr(a,b);
To check if the "FiveM" name appears in the title bar of the window, because usually in this game the title bar also contains updates and so on
so i was googling and i found the GetWindowText
function.
I have ran this code:
HWND foreground = GetForegroundWindow();
char window_title[7];
if (foreground)
{
GetWindowText(foreground, (LPWSTR)window_title, 7);
}
auto output = strstr(window_title, "FiveM");
printf("%d", output);
and got not output, everything was 0, but when i used the function GetWindowTextA()
everything worked fine, so i googled some more about this getwindow function and i found this link and i saw this
#define GetWindowText GetWindowTextA
in a non-Unicode build, GetWindowText and GetWindowTextA are the same thing. [...]
And my build is unicode so that was the problem i had to add that A at the end by why, also why when i get the window text using GetWindowTextW
aka GetWindowText
one char takes more space, i guess it's because of how i cast it right
char window_title[7];
if (foreground)
{
GetWindowTextW(foreground, (LPWSTR)window_title, 7);
}
i'm also confused about why did the strstr()
function rises an memory violation
when printing the output value to the console while just simply reading it doesnt raises any memoy violation