 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Mon Aug 11, 2008 8:04 pm Post subject: [C++ HELP] CreateThread() Help Needed: |
|
|
So, here's the code:
| Code: | // WMPlayer Window.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windowsx.h>
#include "resource.h"
#include <detours.h>
#include <iostream>
#include <sstream>
#include <windows.h>
#include <WINDOWS.H>
#include <stdio.h>
#define sAppName "Hide Ghost"
#define sClassName "HideGhost"
using namespace std;
//Control Declares//
#define IDC_EDIT_CAPTION 1
#define IDC_BUTTON_SHOW 2
#define IDC_BUTTON_HIDE 3
#define IDC_BUTTON_NEW 6
#define IDC_BUTTON_CHANGE 4
#define IDM_MENU_ABOUT 5
#define IDC_STATIC_NEWONE 7
#define GIL 0x0100579C
#define ENABLE_SAVE 0x01CFEA89
#define BUF_SIZE 255
#define MAX_THREADS 3
#define BUF_SIZE 255
DWORD WINAPI MyThreadFunction( LPVOID lpParam );
void ErrorHandler(LPTSTR lpszFunction);
// Sample custom data structure for threads to use.
// This is passed by a void pointer so it can be any data type
// that can be passed using a single void pointer (LPVOID).
typedef struct MyData {
int val1;
int val2;
} MYDATA, *PMYDATA;
static HWND EDIT_CAPTION;
static HWND STATIC_NEWONE;
static HWND BUTTON_SHOW;
static HWND BUTTON_HIDE;
static HWND BUTTON_CHANGE;
static HWND BUTTON_NEW;
static HWND ff8Wnd;
static HANDLE ff8Hnd;
// End Control Declares
PMYDATA pDataArray[MAX_THREADS];
DWORD dwThreadIdArray[MAX_THREADS];
HANDLE hThreadArray[MAX_THREADS];
static HWND lwmhWnd;
static HINSTANCE hInstance;
static HWND MainHwnd;
static LRESULT CALLBACK mainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static int DetectWindow();
static void ChangeCaption();
void DOABOUT(HINSTANCE hInstance);
static DWORD pid;
int WINAPI WinMain (HINSTANCE hinst, HINSTANCE hprevinst, LPSTR lpCmdLine, int cmdShow)
{
for( int i=0; i<MAX_THREADS; i++ )
{
// Allocate memory for thread data.
pDataArray[i] = (PMYDATA) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(MYDATA));
if( pDataArray[i] == NULL )
{
// If the array allocation fails, the system is out of memory
// so there is no point in trying to print an error message.
// Just terminate execution.
ExitProcess(2);
}
}
// Generate unique data for each thread to work with.
pDataArray[i]->val1 = i;
pDataArray[i]->val2 = i+100;
// Create the thread to begin execution on its own.
hThreadArray[i] = CreateThread(
NULL, // default security attributes
0, // use default stack size
MyThreadFunction, // thread function name
pDataArray[i], // argument to thread function
0, // use default creation flags
&dwThreadIdArray[i]); // returns the thread identifier
// Check the return value for success.
// If CreateThread fails, terminate execution.
// This will automatically clean up threads and memory.
if (hprevinst == NULL)
{
WNDCLASS wclass;
memset (&wclass, 0, sizeof(wclass));
wclass.style = CS_HREDRAW | CS_VREDRAW;
wclass.lpfnWndProc = mainWndProc;
wclass.hInstance = hinst;
wclass.hIcon = LoadIcon(hinst,MAKEINTRESOURCE(IDI_ICON1));
wclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wclass.lpszClassName = sClassName;
if (!RegisterClass (&wclass)) return 0;
}
HWND hwnd = CreateWindow(sClassName,sAppName,WS_OVERLAPPED | WS_MINIMIZEBOX |WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_DLGFRAME | WS_BORDER,
CW_USEDEFAULT,CW_USEDEFAULT,130,200,0,0,hinst,0);
hInstance = hinst;
ShowWindow(hwnd, cmdShow);
UpdateWindow(hwnd);
MainHwnd = hwnd;
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
static LRESULT CALLBACK mainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
}
case WM_CLOSE:
{
DestroyWindow(hwnd);
}
case WM_CREATE:
{
HMENU lSysMenu = GetSystemMenu(hwnd,false);
AppendMenu(lSysMenu,MF_SEPARATOR,0,0);
AppendMenu(lSysMenu,MF_STRING,IDM_MENU_ABOUT,"About...");
BUTTON_NEW = CreateWindow("Button","&Hide Gpoopt",WS_CHILD | WS_VISIBLE,1,25,125,25,hwnd,(HMENU)IDC_BUTTON_NEW,hInstance,0);
BUTTON_SHOW = CreateWindow("Button","&Show Ghost",WS_CHILD | WS_VISIBLE,1,50,125,25,hwnd,(HMENU)IDC_BUTTON_SHOW,hInstance,0);
BUTTON_HIDE = CreateWindow("Button","&Hide Ghost",WS_CHILD | WS_VISIBLE,1,1,125,25,hwnd,(HMENU)IDC_BUTTON_HIDE,hInstance,0);
STATIC_NEWONE = CreateWindow("Static","This will be a value", WS_CHILD | WS_VISIBLE, 1,75,200,20,hwnd,(HMENU)IDC_STATIC_NEWONE,hInstance,0);
}
case WM_SYSCOMMAND:
{
switch(LOWORD(wparam))
{
case IDM_MENU_ABOUT:
{
DOABOUT(hInstance);
break;
}
}
break;
}
case WM_COMMAND:
{
switch(HIWORD(wparam))
{
case BN_CLICKED:
{
switch(LOWORD(wparam))
{
case IDC_BUTTON_SHOW:
{
int iresult = 0;
iresult = DetectWindow();
if (iresult == 1)
{
ShowWindow(lwmhWnd, 1);
}
break;
}
case IDC_BUTTON_NEW:
{
WaitForMultipleObjects(MAX_THREADS, hThreadArray, TRUE, INFINITE);
break;
}
case IDC_BUTTON_HIDE:
{
int iresult = 0;
iresult = DetectWindow();
if (iresult == 1)
{
ShowWindow(lwmhWnd, 0);
}
break;
}
case IDC_BUTTON_CHANGE:
{
ChangeCaption();
break;
}
}
}
}
}
}
return DefWindowProc(hwnd,msg,wparam,lparam);
}
static int DetectWindow()
{
lwmhWnd = FindWindow("GhostSoul",NULL);
if (lwmhWnd == 0) // Window Isn't Open
{
return 0;
}
else
{
return 1; // Window is open
}
}
static void ChangeCaption()
{
char sChange[256];
GetDlgItemText(MainHwnd,IDC_EDIT_CAPTION,sChange,256);
SetWindowText(lwmhWnd,sChange);
}
DWORD WINAPI MyThreadFunction(HWND hwnd, LPVOID lpParam )
{
while(1){
DWORD bytes;
int tmpValue;
HWND ff8Wnd;
HANDLE ff8Hnd;
DWORD pid;
//
ff8Wnd = FindWindow("Minesweeper", "Minesweeper"); //or simply FindWindow(NULL, "Final Fantasy VIII"); in msvc++ 6
if(!ff8Wnd)
{
MessageBox(0,"Unable to locate GO window","Uh-Oh!",MB_OK);
}
else
{
GetWindowThreadProcessId(ff8Wnd, &pid);
ff8Hnd = OpenProcess(PROCESS_ALL_ACCESS, false, pid); //now we got process handle, ready to read/write
if(!ff8Hnd) {
MessageBox(0,"Unable to open process","Uh-Oh",0);
}
ReadProcessMemory(ff8Hnd, (void*)GIL, (void*)&tmpValue, 8, &bytes);
// ERROR BELOW
std::ostringstream s;
s << tmpValue << flush; ;
SetDlgItemText(hwnd, IDC_STATIC_NEWONE, s.str().c_str());
}
}
}
|
Here's the error
| Code: | LINK : warning LNK4076: invalid incremental status file "Debug/WMPlayer Window.ilk"; linking nonincrementally
WMPlayer Window.obj : error LNK2001: unresolved external symbol "unsigned long __stdcall MyThreadFunction(void *)" (?MyThreadFunction@@YGKPAX@Z)
Debug/WMPlayer Window.exe : fatal error LNK1120: 1 unresolved externals |
Does anyone know the problem/how to fix it?
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Aug 11, 2008 9:21 pm Post subject: |
|
|
Make sue you have a
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Mon Aug 11, 2008 9:28 pm Post subject: |
|
|
| kitterz wrote: | Make sue you have a
|
That woudn't cause the error.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Tue Aug 12, 2008 2:32 am Post subject: |
|
|
| You've included windows.h 3 times and the declaration at the top is different...
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Tue Aug 12, 2008 2:40 am Post subject: |
|
|
| noz3001 wrote: | | You've included windows.h 3 times and the declaration at the top is different... |
Now THAT would cause a problem.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Tue Aug 12, 2008 5:13 am Post subject: |
|
|
Your prototype for the thread function does not match the thread function itself.
The prototype:
| Code: | | DWORD WINAPI MyThreadFunction( LPVOID lpParam ); |
The function:
| Code: | | DWORD WINAPI MyThreadFunction(HWND hwnd, LPVOID lpParam ) |
The LPVOID lpParam of a thread function is used to pass data to the thread, so you do not need to add another param for the window handle, instead pass it through the lpParam. Look at the params of CreateThread for how to do that.
_________________
- Retired. |
|
| Back to top |
|
 |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Tue Aug 12, 2008 9:08 am Post subject: |
|
|
| After reading about CreateThread() on MSDN, I still cannot quite figure this out, can you give a little more information, or perhaps an example?
|
|
| Back to top |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Tue Aug 12, 2008 9:51 am Post subject: |
|
|
Copy pasting code from MSDN makes very confusing code.
Change | Code: | | DWORD WINAPI MyThreadFunction(HWND hwnd, LPVOID lpParam ) |
to | Code: | | DWORD WINAPI MyThreadFunction(LPVOID lpParam ) |
and
| Code: | SetDlgItemText(hwnd, IDC_STATIC_NEWONE, s.str().c_str());
|
to
| Code: | SetDlgItemText(ff8Wnd, IDC_STATIC_NEWONE, s.str().c_str());
|
|
|
| Back to top |
|
 |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Tue Aug 12, 2008 3:19 pm Post subject: |
|
|
| Thanks, but i already replaced the first one, and the second one is the wrong hwnd. I need the hwnd to my own form, not a another hwnd.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|