FindWindowA Can't find process [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I tried to check value from a game but it seems FindWindowA can't find this game process I tried with other games and it worked. I checked in Process Hacker how the window is called and it still the same as in code but it still didn't work.
First project.cpp : main project file.
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
DWORD pid;
DWORD Ammo = 0x01E7A938;
int MyAmmo;
int main()
{
HWND hWnd = FindWindowA(0, ("War Thunder Client"));
GetWindowThreadProcessId(hWnd, &pid);
HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
while (true)
{
cout << MyAmmo << endl;
Sleep(100);
system("CLS");
}
system("Pause");
}

First, you should check if FindWindowA does actually find your window. If it does not than hWnd will have the value of NULL.
Second, the value of MyAmmo is not set everywhere. It is initalised to 0 because it is a global variable, but otherwise it's value is not changed anywhere.

Related

how can we Hijack DLL to lock all directories in windows to verify [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I mean when we double click a directory,in requests us to verify.I think it can be done by dll-injection.Hope can give some ideas or tutorial.Thanks
Hijack DLL is not required. It use Window Message Hook.
At the first, create DLL that call SetWindowsHookEx.
hHookMsg = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)MsgProc, hInstance, 0);
For example, called install_hook, And MsgProc here
LRESULT CALLBACK MsgProc(INT nCode, WPARAM wp, LPARAM lp) {
CHAR className[256];
MSG *pmsg;
LVHITTESTINFO htif;
POINT pt;
pmsg = (MSG*)lp;
GetClassName(pmsg->hwnd, className, sizeof(className));
if (!strcmp(className, "SysListView32")) {
if (pmsg->message == WM_LBUTTONDBLCLK) {
GetCursorPos((LPPOINT)&pt);
htif.pt = pt;
ScreenToClient(pmsg->hwnd, &htif.pt);
SendMessage(pmsg->hwnd, LVM_HITTEST, 0, (LPARAM)&htif);
if ((htif.flags & LVHT_ONITEM) != 0) {
// you can write action here
}
}
}
return CallNextHookEx( hHookMesg, nCode, wp, lp );
}
And create EXE that call this install_hook.

C++: How might one draw an ASCII character at a specific location in command prompt [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Basically, I want to be able to create a function where I can go:
draw('C', x, y);
draw('h', x+1, y);
draw('a', x+2, y);
draw('r', x+3, y);
and command prompt will display Char at the given x and y position
All I could figure out in my research is that I will have to include <windows.h>, which I have very minimal experience with, and use the pre-defined content in that library.
This might help you get started. See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682073(v=vs.85).aspx for more info.
#include <windows.h>
#include <stdio.h>
void main()
{
HANDLE screenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
CONSOLE_TEXTMODE_BUFFER,
NULL);
if (screenBuffer == INVALID_HANDLE_VALUE)
{
printf("CreateConsoleScreenBuffer failed - (%d)\n", GetLastError());
return;
}
if (!SetConsoleActiveScreenBuffer(screenBuffer))
{
printf("SetConsoleActiveScreenBuffer failed - (%d)\n", GetLastError());
CloseHandle(screenBuffer);
return;
}
for (int x = 0; x < 10; ++x)
{
DWORD numCharsWritten;
WriteConsoleOutputCharacter(screenBuffer, "X", 1, COORD{(short)x, 1}, &numCharsWritten);
Sleep(1000);
}
CloseHandle(screenBuffer);
}

It is possible to declare string[] with a specific name? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm studying the string type, and I stumbled across char string[]. Its confusing and I don't even know what it is. Its strange that i can't declare a string after I use it, because its using like a variable and it doesn't allow me to declare other strings. So how to add a name to that char array? Here is the code so I hope its understandable what I mean. Thanks.
#include "iostream"
#include "string.h"
using namespace std;
int main(){
char string[] = "hello stackoverflow";
string word("hello stackoverflow"); //cant declare "word"
//because i declare it above, and i want to know how to avoid that..
cout<<word;
cout<<string;
}
the code I'm studying is this:
/* Trim fat from windows*/
#define WIN32_LEAN_AND_MEAN
#pragma comment(linker, "/subsystem:windows")
/* Pre-processor directives*/
#include <windows.h>
#include "string.h"
/* Windows Procedure Event Handler*/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT paintStruct;
/* Device Context*/
HDC hDC;
/* Text for display*/
char string [] = "hi im a form"; //this is whats i don't understand what //it is
/* Switch message, condition that is met will execute*/
switch(message)
{
/* Window is being created*/
case WM_CREATE:
return 0;
break;
/* Window is closing*/
case WM_CLOSE:
PostQuitMessage('0');
return 0;
break;
/* Window needs update*/
case WM_PAINT:
hDC = BeginPaint(hwnd,&paintStruct);
/* Set txt color to blue*/
SetTextColor(hDC, COLORREF(0xffff1a));
/* Display text in middle of window*/
TextOut(hDC,150,150,string,sizeof(string)-1); //and here why its //only able to declare it as "string" and not as a name
EndPaint(hwnd, &paintStruct);
return 0;
break;
default:
break;
}
return (DefWindowProc(hwnd,message,wParam,lParam));
}
char c_str[] = "hello";
This declares a variable named c_str of type char [6] a.k.a static array of 6 chars initialized with "hello";
std::string cpp_string("hello");
This declares a variable named cpp_string of type std::string initialized with "hello". If you add using namespace std;, then you can use string instead of std::string.
All declarations of a variable must have the same type. You cannot define a variable multiple times.
You should not declare a variable with the same name as a type.

Window Explorer can't be found [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I'm using VC6 on XP system. I want to find a window whose title matches "C:\", but it can't be found. The return value of hr is -2147023116. Can anybody help?
HWND hwnd = FindWindow(NULL, "C:\\");
IWebBrowserApp *pwba;
HWND hwndindex = NULL;
HRESULT hr = pwba->get_HWND((long*)hwndindex);
if (hwnd == hwndindex)
{
BOOL found = true;
blablabla...
}
below code should work:
INT iIndex = 1;
HWND hwnd = ::GetWindow( ::GetDesktopWindow(), GW_CHILD | GW_HWNDFIRST );
while( hwnd ) {
CString sCaption;
::GetWindowText(hwnd, sCaption.GetBuffer(256), 255);
sCaption.ReleaseBuffer();
//DWORD dwProcessID = 0L;
//::GetWindowThreadProcessId(hwnd, &dwProcessID);
//CString sExePath;
//::GetModuleFileName((HMODULE)dwProcessID, sExePath.GetBuffer(MAX_PATH), MAX_PATH);
//sExePath.ReleaseBuffer();
if ( sCaption.Find(_T("c:\\")) != -1 ) {
// found you!
}
hwnd = ::GetWindow( hwnd, GW_HWNDNEXT );
}
HRESULT hr = pwba->get_HWND((long*)&hwndindex);
Problem solved! I missed one important "&"

Never ending Win32 Message loop [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
I have the following code:
MSG mssg;
// run till completed
while (true) {
// is there a message to process?
while(PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
}
if(mssg.message == WM_QUIT){
break;
}
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
Once it enters the inner loop with peekmessage it does not exit until the application is closed. Thus if I place a breakpoint at Render() and OnUpdate(), they will never be called during the lifetime of the application.
This runs contrary to what I'm being told here and here. How do I do this properly?
A typical game loop has this form:
MSG mssg;
bool notdone = true;
// run till completed
while ( notdone ) {
// is there a message to process?
if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) {
if (mssg.message == WM_QUIT) notdone = false;
// dispatch the message
TranslateMessage(&mssg);
DispatchMessage(&mssg);
} else {
// our stuff will go here!!
Render();
listeners->OnUpdate();
}
}