|
You last visited: Today at 09:15
Advertisement
[C++]Problem FindWindow
Discussion on [C++]Problem FindWindow within the C/C++ forum part of the Coders Den category.
04/30/2011, 21:43
|
#1
|
elite*gold: 0
Join Date: Jan 2010
Posts: 112
Received Thanks: 564
|
[C++]Problem FindWindow
hey wie der titel schon sagt hab ich ein problem mit findwindow
unzwar immer wenn ich 4story_gsp ( fenstername von 4story spiel )
aufrufen will hwnd = FindWindow(0,L"4Story_GSP");
setzt sich der processhandel auf 0000000000 bei anderen processen geht das ohne probleme nur da nicht liegt es vllt an dem _ oder an was anderes ? bitte um ein paar ideen voran es liegen könnte :P
|
|
|
04/30/2011, 21:46
|
#2
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,907
Received Thanks: 25,408
|
könntest du es bitte lassen zu jedem scheiß copy&paste problem nen neuen thread aufzumachen und endlich die verdammte sprache lernen, bevor du hacks schreiben willst?
es hat so keinen sinn...
1. hat der process handle nix mit FindWindow zutun, meinst du also wirklich den oder den Window Handle?
2. das kann viele gründe haben, was sagt GetLastError?
|
|
|
04/30/2011, 22:05
|
#3
|
elite*gold: 0
Join Date: Jan 2010
Posts: 112
Received Thanks: 564
|
problem tritt nur auf wenn ich FindWindow änder
hwnd = FindWindow
GetWindowThreadProcessId( hwnd,&Id)
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, Id);
die haben nix miteinander zu tun ?!     :  
|
|
|
04/30/2011, 22:27
|
#4
|
elite*gold: 0
Join Date: Nov 2009
Posts: 343
Received Thanks: 45
|
Poste mal den Code richtig mit Code Tags.
MfG
|
|
|
04/30/2011, 23:09
|
#5
|
elite*gold: 0
Join Date: Jan 2010
Posts: 112
Received Thanks: 564
|
Quote:
Originally Posted by yihaaa
Poste mal den Code richtig mit Code Tags.
MfG
|
Code:
#include <windows.h> // Hier sind die Funktionen die wir später noch brauchen
#include <iostream> // Sollte klar sein
using namespace std; // Sollte auch klar sein ...
int main() // Unsere Main Funktion...
{
HWND hwnd; // Unsere Variable die das Fensterhandle speichert.
hwnd = FindWindow(0,L"4Story_GSP");
DWORD Id; // Die ID wird in einer Variable des Typ's DWORD gespeichert.
HANDLE ProcessHandle;
unsigned long address0 = 0x006EFFFC;
unsigned long offset2 = 0x604;
unsigned long offset = 0x188;
unsigned long address1 ;
unsigned long address2 ;
DWORD numBytesRead;
int hp ;
// Der Fenstertitel vom Solitärfenster ist "Solitär". Das erste Parameter ist der "ClassName" den wir aber getrost ignorieren können. Das zweite Parameter ist unser Fenstername. Das "L" steht für eine Typkonvertierung..
if(!hwnd) // Also das Fenster nicht vorhanden ist...
{
cout << "Solitär nicht gefunden!" << endl; // Gebe das aus
cin.get();
}
else // ansonsten...
{
cout << "Solitär gefunden!" << endl; // gebe das aus
cout << "Fensterhandle: " << hwnd << endl; // Wir können uns das Handle auch nochmal angucken ...
GetWindowThreadProcessId(hwnd,&Id); // Mit GetWindowThreadProcessId kann man die ID herausfinden. Das erste Parameter ist unser Fensterhandle. Das zweite gibt an, wo die ID gespeichert werden soll.
cout << GetLastError <<
cout << "ID "<< Id << endl;
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, Id);
cout << "ProcessHandle: " << ProcessHandle << endl;
ReadProcessMemory(ProcessHandle, (LPCVOID)address0, &address1, sizeof(long), &numBytesRead);
address1 = address1+offset ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address1, &address2, sizeof(long), &numBytesRead);
address2 = address2+offset2 ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address2, &hp, sizeof(int), &numBytesRead);
cout << "Punkte : " <<hp<< endl;
cin.get();// Damit sich unser Programm nicht sofort schließt...
}
}
|
|
|
04/30/2011, 23:18
|
#6
|
elite*gold: 0
Join Date: Nov 2009
Posts: 343
Received Thanks: 45
|
Versuchs mal damit:
Code:
int GetProcessID( char* pName )
{
HANDLE hProcessSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPALL, 0 );
PROCESSENTRY32 ProcessEntry = { 0 };
ProcessEntry.dwSize = sizeof( ProcessEntry );
BOOL Return = Process32First( hProcessSnapShot, &ProcessEntry );
do
{
if ( strcmp ( ProcessEntry.szExeFile, pName ) == 0 )
{
return ( int )ProcessEntry.th32ProcessID;
}
}while( Process32Next( hProcessSnapShot, &ProcessEntry ) );
CloseHandle( hProcessSnapShot );
return -1;
}
Du musst noch eine Header einbinden, den musste dir aber selbst raussuchen. Etwas sollte man immerhin machen, wenn man schon alles c&p übernimmt.
MfG
|
|
|
04/30/2011, 23:28
|
#7
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,907
Received Thanks: 25,408
|
Quote:
Originally Posted by Evilkingg
problem tritt nur auf wenn ich FindWindow änder
hwnd = FindWindow
GetWindowThreadProcessId(hwnd,&Id)
ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, false, Id);
|
was sagt GetLastError nach FindWindow? was sagt es nach GetWindowThreadProcessId? was sagt es nach OpenProcess?
Quote:
die haben nix miteinander zu tun ?!    : 
|
Jo haben sie nicht.
Quote:
|
Du musst noch eine Header einbinden, den musste dir aber selbst raussuchen. Etwas sollte man immerhin machen, wenn man schon alles c&p übernimmt.
|
find ich albern, du solltest ihm lieber den header sagen und nicht, wie man ihn benutzt, als so rum.
außerdem kann man FindWindow bei konstantem Window Title genau so gut einsetzen und es spart Code-Zeilen und Laufzeit
|
|
|
04/30/2011, 23:53
|
#8
|
elite*gold: 0
Join Date: Jan 2010
Posts: 112
Received Thanks: 564
|
danke das du versuchs mir zu helfen :P
hier ein pic hab jetzt die GetLastError drine
|
|
|
05/01/2011, 00:33
|
#9
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,907
Received Thanks: 25,408
|
Ähm, GetLastError ist ne Funktion, also GetLastError(), das weißt du oder?
Das da sieht mir eher danach aus, dass du die Adresse der Funktion im Speicher ausgibst, sprich die Klammern weglässt ;O
|
|
|
05/01/2011, 00:54
|
#10
|
elite*gold: 0
Join Date: Jan 2010
Posts: 112
Received Thanks: 564
|
achso meinst du das dann vllt so  ?
|
|
|
05/01/2011, 01:35
|
#11
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,907
Received Thanks: 25,408
|
wie du leicht entnehmen kannst, starte das programm als admin (sollte eigentlich eh klar sein...)
und nun lern die sprache ;<
|
|
|
05/01/2011, 03:57
|
#12
|
elite*gold: 0
Join Date: Mar 2009
Posts: 7,260
Received Thanks: 33,149
|
Bei dem Problem hätte dir hier nicht wirklich jemand helfen können. Es gibt nur einen Fehler, du addierst die Offsets falsch. Funktionieren würde es so:
PHP Code:
ReadProcessMemory(ProcessHandle, (LPCVOID)address0, &address1, sizeof(long), &numBytesRead);
address1 = address1+offset2 ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address1, &address2, sizeof(long), &numBytesRead);
address2 = address2+offset ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address2, &hp, sizeof(int), &numBytesRead);
Zusammen kopiert sieht das ganze natürlich nicht mehr so schön aus, hier noch mal etwas "sauberer":
PHP Code:
#include <windows.h>
#include <iostream>
using namespace std;
DWORD Base = 0x6EFFFC;
DWORD Offset[2] = {0x604, 0x188};
int main(){
HWND hWnd = FindWindow(0, "4Story_GSP");
if(!hWnd){
cout << "4Story EG wurde nicht gefunden!" << endl;
}else{
DWORD ProcessId;
GetWindowThreadProcessId(hWnd, &ProcessId);
HANDLE hProcess = OpenProcess(0x1F0FFF, false, ProcessId);
DWORD Address, V_HP;
ReadProcessMemory(hProcess, (LPCVOID)Base, &Address, 4, 0);
Address = Address + Offset[0];
ReadProcessMemory(hProcess, (LPCVOID)Address, &Address, 4, 0);
Address = Address + Offset[1];
ReadProcessMemory(hProcess, (LPCVOID)Address, &V_HP, 4, 0);
cout << "HP: " << V_HP << endl;
}
system("PAUSE");
return 0;
}
Quote:
Originally Posted by MrSm!th
und nun lern die sprache ;<
|
|
|
|
05/01/2011, 10:25
|
#13
|
elite*gold: 49
Join Date: Oct 2010
Posts: 269
Received Thanks: 308
|
PHP Code:
ReadProcessMemory(ProcessHandle, (LPCVOID)address0, &address1, sizeof(long), &numBytesRead); address1 = address1+offset2 ; ReadProcessMemory(ProcessHandle, (LPCVOID)address1, &address2, sizeof(long), &numBytesRead); address2 = address2+offset ; ReadProcessMemory(ProcessHandle, (LPCVOID)address2, &hp, sizeof(int), &numBytesRead);
Don't use this. Try to use that code:
PHP Code:
UINT_PTR DeRef( UINT_PTR _uiptrPointer ) { UINT_PTR uiptrRet; if ( !::ReadProcessMemory( hProcess, reinterpret_cast<LPVOID>(_uiptrPointer), &uiptrRet, sizeof( uiptrRet ), NULL ) ) { return 0UL; } return uiptrRet; }
So...
PHP Code:
addy1 = DeRef( DeRef( DeRef( 0x123456 ) + 0x123 ) + 0x123 ) + 0x123; WriteProcessMemory(hProcess,(LPVOID)addy,&value1,4,NULL);
|
|
|
05/01/2011, 11:15
|
#14
|
elite*gold: 42
Join Date: Jun 2008
Posts: 5,425
Received Thanks: 1,888
|
Quote:
Originally Posted by KillerDeluxe
Bei dem Problem hätte dir hier nicht wirklich jemand helfen können. Es gibt nur einen Fehler, du addierst die Offsets falsch. Funktionieren würde es so:
PHP Code:
ReadProcessMemory(ProcessHandle, (LPCVOID)address0, &address1, sizeof(long), &numBytesRead);
address1 = address1+offset2 ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address1, &address2, sizeof(long), &numBytesRead);
address2 = address2+offset ;
ReadProcessMemory(ProcessHandle, (LPCVOID)address2, &hp, sizeof(int), &numBytesRead);
Zusammen kopiert sieht das ganze natürlich nicht mehr so schön aus, hier noch mal etwas "sauberer":
PHP Code:
#include <windows.h>
#include <iostream>
using namespace std;
DWORD Base = 0x6EFFFC;
DWORD Offset[2] = {0x604, 0x188};
int main(){
HWND hWnd = FindWindow(0, "4Story_GSP");
if(!hWnd){
cout << "4Story EG wurde nicht gefunden!" << endl;
}else{
DWORD ProcessId;
GetWindowThreadProcessId(hWnd, &ProcessId);
HANDLE hProcess = OpenProcess(0x1F0FFF, false, ProcessId);
DWORD Address, V_HP;
ReadProcessMemory(hProcess, (LPCVOID)Base, &Address, 4, 0);
Address = Address + Offset[0];
ReadProcessMemory(hProcess, (LPCVOID)Address, &Address, 4, 0);
Address = Address + Offset[1];
ReadProcessMemory(hProcess, (LPCVOID)Address, &V_HP, 4, 0);
cout << "HP: " << V_HP << endl;
}
system("PAUSE");
return 0;
}
|
Schonmal was von UINT_PTR gehört?
|
|
|
05/01/2011, 11:31
|
#15
|
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
|
Quote:
|
Schonmal was von UINT_PTR gehört?
|
Ich nicht. Deshalb habe ich mal geschwind die MSDN besucht:
Quote:
|
typedef unsigned int UINT_PTR;
|
und
Quote:
|
typedef unsigned int UINT;
|
und
Quote:
|
typedef unsigned long DWORD;
|
Und jetzt darfst du mir erklären, warum man hier lieber UINT_PTR nehmen sollte. Ich verstehe es nämlich nicht, was mich davon abhalten sollte, einfach "unsigned int" zu verwenden, ist doch alles (fast) das gleiche... o,ô
|
|
|
 |
|
Similar Threads
|
C++ Winapi FindWindow Problem
01/27/2011 - C/C++ - 0 Replies
Hi,
hab folgendes Problem:
Will ein Fenster umbennen, das will aber nicht wirklich.
#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
|
[C++]FindWindow findet nichts.
09/13/2010 - C/C++ - 18 Replies
http://www.paste-code.com/paste.php?id=kbC95ZHRry
Aber sobald ich zum Beispiel :
FindWindow(NULL,"PVP.net-Client") angebe, findet er es und gibt mir dann die HWND aus.
Wo liegt das problem?
Ich hab es auch schon so:
FindWindow("\\„League of Legends\\“-Startprogramm - 1,0,0,31 - ", NULL); versucht, geht trozdem nicht :/
|
FindWindow parameter richtig nutzen...
06/15/2010 - General Coding - 14 Replies
HWND xxx = FindWindow(NULL ,"XXX");
ShowWindow(xxx, SW_RESTORE);
FindWindowW': Konvertierung des Parameters 2 von 'const char ' in 'LPCWSTR' nicht möglich
<<
Diese meldung beim compilen
|
Kal FindWindow help
12/15/2008 - Kal Online - 2 Replies
yup, what the title is saying, i'm trying to find the window of kalonline ... but failed.... dont work idk why, name is correct.... hope someone can help
Source:
// Basic Include's
#include <windows.h>
#include <iostream>
// The Namespace
|
All times are GMT +1. The time now is 09:16.
|
|