Subscribe to News

Process List on Windows Mobile

Author : Ester Artieda

From TechnologicalWiki

Jump to: navigation, search


Contents

[edit] Introduction

One of the most useful tools on our PC is the task manager, because it gives information about all the applications are running on that time.

Windows mobile devices don't provide their systems with that kind of tool, but some times it's necessary to know the current process the system is running.

This article shows how to use the tool help library on a C++ application, to know the active programs.

[edit] Library

As it have been said on the last paragraph, the library we are going to use to know the active process is Toolhelp32.dll. This library doesn't give application names, it shows process names and some of the data associated to them like the PID(process identificatior), the number of threads associated to each process, the PID of the parent and the priority of the threads. In addition to this, we can get info about a particular thread or about the module and the heap.

[edit] Code

This code is all the necessary to know what process are running on your device.

     HANDLE snapHand;
     PROCESSENTRY32 procEntry;
     procEntry.dwSize=sizeof(PROCESSENTRY32);
     snapHand = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | 0x40000000, 0);
     string currentPIDs;
     if(INVALID_HANDLE_VALUE == snapHand)
     {
         int j = GetLastError();
         return -1;
     }
     if(!Process32First(snapHand,&procEntry))
       {
           if(GetLastError() ==  ERROR_NO_MORE_FILES)
             {
                //SendMessage(hListWnd,LB_ADDSTRING,0,LPARAM(TEXT("EndOfListing")));
             }
           return -1;
       }
     procEntry.dwSize = sizeof(procEntry);
     char PIDS[500];
     do
       {
         char pid[40];
         sprintf(pid,"%u",procEntry.th32ProcessID);
         strcat( PIDS,pid);
         strcat( PIDS,";");
         //currentPIDs=currentPIDs+string(pid)+";";
         //delete[] pid;
       }while(Process32Next(snapHand,&procEntry));
     CloseToolhelp32Snapshot(snapHand);

[edit] Get more info with toolhelp32.dll

If you need to get information about a particular thread, module or heap, you only have to replace process intructions by thread, heap or module ones. All the info you need about Toolhelp32.dll is on: http://msdn.microsoft.com/en-us/library/ms686840(VS.85).aspx

Main Collaborators