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 


listing process question
Goto page 1, 2  Next
 
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: Mon May 12, 2008 3:27 am    Post subject: listing process question Reply with quote

I'm trying to make a program, and part of it needs to list out all the running processes. But whenever I compile I get the same error for times, and I don't understand what it means. Everything looks fine to me, and nothing like this has ever happened to me before. Here's my code and the error:

Code:

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


Quote:

------ Build started: Project: Process Killer, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\oib\desktop\win32 temp\main.cpp(50) : error C2360: initialization of 'hSnapshot' is skipped by 'case' label
c:\documents and settings\oib\desktop\win32 temp\main.cpp(41) : see declaration of 'hSnapshot'
c:\documents and settings\oib\desktop\win32 temp\main.cpp(60) : error C2360: initialization of 'hSnapshot' is skipped by 'case' label
c:\documents and settings\oib\desktop\win32 temp\main.cpp(41) : see declaration of 'hSnapshot'
c:\documents and settings\oib\desktop\win32 temp\main.cpp(62) : error C2360: initialization of 'hSnapshot' is skipped by 'case' label
c:\documents and settings\oib\desktop\win32 temp\main.cpp(41) : see declaration of 'hSnapshot'
c:\documents and settings\oib\desktop\win32 temp\main.cpp(65) : error C2361: initialization of 'hSnapshot' is skipped by 'default' label
c:\documents and settings\oib\desktop\win32 temp\main.cpp(41) : see declaration of 'hSnapshot'
Build log was saved at "file://c:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\Process Killer\Process Killer\Debug\BuildLog.htm"
Process Killer - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

_________________


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
Ferocious
Advanced Cheater
Reputation: 0

Joined: 06 Feb 2008
Posts: 54

PostPosted: Mon May 12, 2008 3:34 am    Post subject: Reply with quote

try not puting this in a switch case, try creating a wrapper, and call the wrapper instead.
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: Mon May 12, 2008 3:40 am    Post subject: Reply with quote

*cough**cough*(feel really stupid right now) Eh, a wrapper? Tried looking up and didn't find anything pertaining to computers. I've seen tutorials for interesting things that happen to use wrappers, but a definition of a wrapper would be nice xD.
_________________


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
Ferocious
Advanced Cheater
Reputation: 0

Joined: 06 Feb 2008
Posts: 54

PostPosted: Mon May 12, 2008 3:47 am    Post subject: Reply with quote

here, this is my wrapper to get an instance of process id.

Code:
BOOL GetProcessID(LPCWSTR ProcessName, int *pProcessID)
{
   HANDLE hProcessSnap;
   PROCESSENTRY32 ProcessEntry;
   BOOL ProcessFound = FALSE;
   
   while (ProcessFound == FALSE)
   {
      hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
      ProcessEntry.dwSize = sizeof(PROCESSENTRY32);

      if (!Process32First(hProcessSnap, &ProcessEntry))
      {
         CloseHandle(hProcessSnap);
      }

      do
      {
         if (lstrcmpi(ProcessEntry.szExeFile, ProcessName) == 0)
         {
            *pProcessID = ProcessEntry.th32ProcessID;
            ProcessFound = TRUE;
            CloseHandle(hProcessSnap);
            return TRUE;
         }
      } while (Process32Next(hProcessSnap, &ProcessEntry));
   }

   *pProcessID = -1;
   CloseHandle(hProcessSnap);
   return FALSE;
}


wrapper is a function that calls sets of functions to achieve its mission.
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: Mon May 12, 2008 4:02 am    Post subject: Reply with quote

Ok, I have a question. I made my wrapper. Got everything fixed so there are no errors and warnings. But how do I add scrollbars to my listbox. Because you can't see all the processes being listed. There didn't seem to be an LBS_VSCROLL or LBS_HSCROLL or anything like that that I could use in CreateWindowEx(). So yeah, how?
_________________


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: 8588
Location: 127.0.0.1

PostPosted: Mon May 12, 2008 4:18 am    Post subject: Reply with quote

oib111 wrote:
Ok, I have a question. I made my wrapper. Got everything fixed so there are no errors and warnings. But how do I add scrollbars to my listbox. Because you can't see all the processes being listed. There didn't seem to be an LBS_VSCROLL or LBS_HSCROLL or anything like that that I could use in CreateWindowEx(). So yeah, how?


Add WS_VSCROLL to your style for the listbox.

_________________
- 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: Mon May 12, 2008 4:19 am    Post subject: Reply with quote

Oh my god...I have some crazy weird errors now. As soon as I put this into my code it like destroyed everything o.o

Code:

BOOL PK(char *szExe) {
   HANDLE hProcess;
   PROCESSENTRY32 PKpe32;
   PKpe32.dwSize = sizeof(PROCESSENTRY32);
   HANDLE PKhSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   Process32First(PKhSnapshot, &PKpe32);
   do {
      if(strcmp(PKpe32.szExeFile, szExe) == 0) {
         hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, PKpe32.th32ProcessID);
         TerminateProcess(hProcess, 0);
         CloseHandle(hProcess);
         CloseHandle(PKhSnapshot);
         return TRUE;
   } while(Process32Next(PKhSnapshot, &PKpe32));
   CloseHandle(PKhSnapshot);
   return FALSE;
}


Quote:

------ Build started: Project: Process Killer, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(47) : error C2226: syntax error : unexpected type 'LRESULT'
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(4Cool : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(49) : error C2065: 'message' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(49) : error C2050: switch expression not integral
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(61) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(62) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(63) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(64) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(72) : error C2065: 'wParam' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(82) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(87) : error C2065: 'hwnd' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(87) : error C2065: 'message' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(87) : error C2065: 'wParam' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(87) : error C2065: 'lParam' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(9Cool : error C2601: 'WinMain' : local function definitions are illegal
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(27): this line contains a '{' which has not yet been matched
c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(171) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(27)' was matched
Build log was saved at "file://c:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\Process Killer\Process Killer\Debug\BuildLog.htm"
Process Killer - 16 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


_________________


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: 8588
Location: 127.0.0.1

PostPosted: Mon May 12, 2008 5:01 am    Post subject: Reply with quote

Looks like you messed something up in your case, not in that function.
_________________
- 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: Mon May 12, 2008 5:04 am    Post subject: Reply with quote

You're right. But there's nothing wrong with my switch case (at least I don't think)...

Code:

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
      case WM_CREATE:
         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");

         HWND hButtonPK, hButtonA, hStatic;
         hList = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_SORT, 25, 35, 200, 200, hwnd, (HMENU)IDC_MAIN_LIST, GetModuleHandle(NULL), NULL);
         hStatic = CreateWindowEx(NULL, "STATIC", "Processes:", WS_CHILD | WS_VISIBLE, 25, 15, 65, 20, hwnd, (HMENU)IDC_MAIN_STATIC, GetModuleHandle(NULL), NULL);
         hButtonPK = CreateWindowEx(NULL, "BUTTON", "Kill Process", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 230, 33, 75, 100, hwnd, (HMENU)IDC_PK_BUTTON, GetModuleHandle(NULL), NULL);
         hButtonA = CreateWindowEx(NULL, "BUTTON", "About", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 230, 135, 75, 100, hwnd, (HMENU)IDC_ABOUT_BUTTON, GetModuleHandle(NULL), NULL);
         SendMessage(hList, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hStatic, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hButtonPK, WM_SETFONT, (WPARAM)hfFont, NULL);
         SendMessage(hButtonA, WM_SETFONT, (WPARAM)hfFont, NULL);
         ListProcess();
         break;
      case WM_COMMAND:
         switch(LOWORD(wParam)) {
            case IDC_PK_BUTTON:
               MessageBox(NULL, "Clicked!", "Click", MB_OK);
               break;
            case IDC_ABOUT_BUTTON:
               MessageBox(NULL, "Clicked!", "Click", MB_OK);
               break;
         }
      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;
}

_________________


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
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon May 12, 2008 5:13 am    Post subject: Reply with quote

Entire source?


You missed a semi colon before this i think and it's waiting for a dif command

i think

c:\documents and settings\oib\my documents\visual studio 2008\projects\process killer\process killer\main.cpp(27): this line contains a '{' which has not yet been matched

This means that on 27 you need to find where the } will go and it's all fixed. It's running your WHOLE program code inside a local function and it's fucking it all up.

_________________
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: Mon May 12, 2008 5:21 am    Post subject: Reply with quote

Haha thanks. You know what it was. I forgot a '}' (as you said and VC++) during my if statement. It's cool now. Thanks for your help blank.
_________________


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: Mon May 12, 2008 8:04 am    Post subject: Reply with quote

if you want to initialize variables in a switch case you must include brace's after the case

example:

Code:
case 1:
{
    int i = 0;
    break;
}

_________________
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: Mon May 12, 2008 8:46 am    Post subject: Reply with quote

Ok. If I wanted to get the text of the selected item would I do something like this?

Code:

char *szExe;
int index = SendMessage(hList, LB_GETCURSEL, NULL, NULL);
SendMessage(hList, LB_GETTEXT, (WPARAM)index, (LPARAM)szExe);

_________________


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: Mon May 12, 2008 1:43 pm    Post subject: Reply with quote

exactly Smile
_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Mon May 12, 2008 1:48 pm    Post subject: Reply with quote

Use LB_GETTEXTLEN then allocate the proper size of the string needed. You can use various things to do that, such as new, GlobalAlloc, HeapAlloc, and so on.

For example, using new would look something like:

Code:
int iLength = SendMessage( hWndList, LB_GETTEXTLEN, (WPARAM)iIndex, (LPARAM)NULL );
TCHAR* tszListString = new TCHAR[ iLength + 1 ];
SendMessage( hWndList, LB_GETTEXT, (WPARAM)iIndex, (LPARAM)tszListString );

// Do what ever with the string here ...

delete[] tszListString

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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