Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


function help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 24, 2008 10:38 am    Post subject: function help Reply with quote

I'm making a program and one of my functions needs access to one of the variables (hwnd) in my main function (WinMain). If I keep hwnd in WinMain I get a compilation error because my function can't access the other variable (duh). And then if I set hwnd to be a global variable I get some weird runtime error.



Quote:

'Dll Injector.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\Dll Injector\Debug\Dll Injector.exe', Symbols loaded.
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\uxtheme.dll'
'Dll Injector.exe': Loaded 'D:\WINDOWS\BricoPacks\Vista Inspirat 2\RocketDock\RocketDock.dll', Binary was not built with debug information.
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\psapi.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msctf.dll'
'Dll Injector.exe': Loaded 'C:\Program Files\Seekmo\bin\10.0.406.0\HostOE.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\ole32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\oleaut32.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\version.dll'
'Dll Injector.exe': Unloaded 'C:\WINDOWS\system32\version.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll'
'Dll Injector.exe': Loaded 'C:\WINDOWS\system32\msctfime.ime'
HEAP[Dll Injector.exe]: HEAP: Free Heap block 166df0 modified at 166e04 after it was freed
Windows has triggered a breakpoint in Dll Injector.exe.

This may be due to a corruption of the heap, which indicates a bug in Dll Injector.exe or any of the DLLs it has loaded.

This may also be due to the user pressing F12 while Dll Injector.exe has focus.

The output window may have more diagnostic information.


Quote:

+ &messages 0x0013fedc {msg=0x0000c0f3 wp=0x00000000 lp=0x00000000} tagMSG *

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat May 24, 2008 10:41 am    Post subject: Reply with quote

Post the code as well.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 24, 2008 10:44 am    Post subject: Reply with quote

GetIndexName
Code:

void GetIndexName() {
   char ExeFile[255];
   int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
   if(index != LB_ERR) {
      SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)ExeFile);
      SetDlgItemText(hwnd, IDC_PROCESS_EDIT, ExeFile);
   }
}


My global variables
Code:

/*  Make the class name into a global variable  */
char szClassName[ ] = "DllInject";
HWND hList;
HWND hwnd;               /* This is the handle for our window */
char path[MAX_PATH];

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Sat May 24, 2008 12:09 pm    Post subject: Reply with quote

you still haven't posted your whole code but i think i know the problem. Do it like this.

Make a new global variable

HWND hWND;

In your winmain function,after WM_INITDIALOG or WM_CREATE or just at the start of function, add

hWND = hwnd;(hwnd should be the winmain hwnd parameter/argument).You can use hWND anywhere now Smile.

Hope it helps.

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 24, 2008 12:24 pm    Post subject: Reply with quote

Thanks STN it's working now. But now I have a weird bug. Basically I'm trying to make it so when you click or double click on a process name in the list box it will list it out in my process name edit box. But the bug is, is that it will do that. But you have to click/double click and then hover your mouse over a button to make it list it o.o Anyone know how to fix this?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat May 24, 2008 12:38 pm    Post subject: Reply with quote

if you don't show us the full source we can't help you.
_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 24, 2008 12:43 pm    Post subject: Reply with quote

Code:

#include <windows.h>
#include <commctrl.h>
#include "dllinject.h"
#define IDC_OPEN_BUTTON 100
#define IDC_INJECT_BUTTON 101
#define IDC_REFRESH_BUTTON 102
#define IDC_DLLPATH_EDIT 103
#define IDC_PROCESS_EDIT 104
#define IDC_PROCESS_LIST 105
#define IDC_MAIN_GROUP 106
#define IDC_PROCESS_GROUP 107
#define IDC_MAIN_STATIC 108
#define IDC_PROCESS_STATIC 109
#pragma comment (lib,"COMCTL32.lib") // might not need...
#pragma comment (linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

/*  Make the class name into a global variable  */
char szClassName[ ] = "DllInject";
HWND hList;
HWND hWND;
char path[MAX_PATH];

void ListProcess() {
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   PROCESSENTRY32 pe32;
   pe32.dwSize = sizeof(PROCESSENTRY32);
   Process32First(hSnapshot, &pe32);
   do {
      SendMessage(hList, LB_ADDSTRING, NULL, (LPARAM)pe32.szExeFile);
   } while(Process32Next(hSnapshot, &pe32));
   CloseHandle(hSnapshot);
}

void GetIndexName() {
   char ExeFile[255];
   int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
   if(index != LB_ERR) {
      SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)ExeFile);
      SetDlgItemText(hWND, IDC_PROCESS_EDIT, ExeFile);
   }
}

void GetIndexNameAndInject() {
   char ExeFile[255];
   int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
   if(index != LB_ERR) {
      SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)ExeFile);
      InjectDLL(ExeFile, path);
   }
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
      case WM_CREATE:
         HWND hOpen, hInject, hRefresh, hDllpath, hPEdit, hGroup, hPGroup, hStatic, hPStatic;
         HFONT hfFont;
         HDC dc;
         LONG lfHeight;

         dc = GetDC(NULL);
         lfHeight = -MulDiv(10, GetDeviceCaps(dc, LOGPIXELSY), 72);
         hfFont = CreateFont(lfHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");

         hOpen = CreateWindowEx(NULL, "BUTTON", "Open Dll", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 50, 60, 80, 35, hwnd, (HMENU)IDC_OPEN_BUTTON, GetModuleHandle(NULL), NULL);
         hInject = CreateWindowEx(NULL, "BUTTON", "Inject DLL", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 140, 60, 80, 35, hwnd, (HMENU)IDC_INJECT_BUTTON, GetModuleHandle(NULL), NULL);
         hDllpath = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 50, 100, 170, 20, hwnd, (HMENU)IDC_DLLPATH_EDIT, GetModuleHandle(NULL), NULL);
         hPEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | WS_VISIBLE, 50, 220, 170, 20, hwnd, (HMENU)IDC_PROCESS_EDIT, GetModuleHandle(NULL), NULL);
         hPStatic = CreateWindowEx(NULL, "STATIC", "Process Name", WS_CHILD | WS_VISIBLE, 50, 200, 150, 20, hwnd, (HMENU)IDC_PROCESS_STATIC, GetModuleHandle(NULL), NULL);
         hList = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_SORT | LBS_NOTIFY, 250, 80, 225, 190, hwnd, (HMENU)IDC_PROCESS_LIST, GetModuleHandle(NULL), NULL);
         hStatic = CreateWindowEx(NULL, "STATIC", "Processes", WS_CHILD | WS_VISIBLE, 250, 60, 70, 20, hwnd, (HMENU)IDC_MAIN_STATIC, GetModuleHandle(NULL), NULL);
         hRefresh = CreateWindowEx(NULL, "BUTTON", "Refresh Process List", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 325, 60, 150, 20, hwnd, (HMENU)IDC_REFRESH_BUTTON, GetModuleHandle(NULL), NULL);
         SendMessage(hOpen, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hInject, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hDllpath, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hPEdit, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hPStatic, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hList, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hStatic, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hRefresh, WM_SETFONT, (WPARAM)hfFont, NULL);
         ListProcess();
         hWND = hwnd;
         break;
      case WM_NOTIFY:
         GetIndexName();
         break;
      case WM_CLOSE:
         DestroyWindow(hwnd);
        case WM_DESTROY:
            PostQuitMessage(0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow)

{
    INITCOMMONCONTROLSEX init;
   init.dwSize = sizeof(INITCOMMONCONTROLSEX);
   init.dwICC = ICC_STANDARD_CLASSES;
   InitCommonControlsEx(&init);

   HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = 0;
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) (COLOR_BTNSHADOW);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
   {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Dll Injector",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           500,                 /* The programs width */
           300,                 /* and height in pixels */
           NULL,        /* The window isn't a child */
           NULL,                /* No menu */
           hInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
       
   if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);
   UpdateWindow(hwnd);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0) > 0)
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }
    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat May 24, 2008 12:51 pm    Post subject: Reply with quote

Code:
case WM_NOTIFY:
      switch ( LOWORD(wParam) )
      {
      case IDC_LIST1:
         {
            if ( ((LPNMHDR)lParam)->code == NM_DBLCLK )
            {
               if ( AttachProc() )
                  SendMessage( hPList, WM_CLOSE, 0, 0 );
               else
                  break;
            }
         }
         break;
      }


Make sure you filter it like this or else any notification the window sends will execute that function.
This was an example from the process list i made for my attempted CE which i gave up on Razz

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat May 24, 2008 1:00 pm    Post subject: Reply with quote

Now it doesn't do anything. Or am I filtering it wrong?

Code:

case WM_NOTIFY:
   switch(LOWORD(wParam)) {
      case IDC_PROCESS_LIST:
         GetIndexName();
         break;
   }
break;

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites