Fails to convert process name to wxString

Eric Jensen ej at xe847.com
Thu Nov 1 05:57:13 PDT 2007


EI> Problematic OS:
EI> Win XP SP2, gdb 6.6, gcc 3.4.5 mingw, wx 2.8.4, Debug/Release Unicode
EI> monolithic dll

EI> I am trying to get a process name by its PID, however I fails to convert the
EI> string to proper wxString on Windows.

EI> I am using WinAPI  (windows)/ ps command (linux), my code looks something
EI> like this:

EI> PROCESSENTRY32 pe;
EI> wxZeroMemory(pe);
EI> pe.dwSize = sizeof(PROCESSENTRY32);

EI> if (!lpfProcess32First(hProcessSnap, &pe)) {
EI>     CloseHandle (hProcessSnap);
EI>     return wxEmptyString;
EI> }

EI> //Loop over and search for our process ID
EI> bool cont(true);
EI> while( cont ){
EI>     wxLogMessage(pe.szExeFile);
EI>     if(pe.th32ProcessID == (DWORD)pid){
EI>         //Conversion need to be taken here fro pe.szExeFile to wxString
EI>         CloseHandle (hProcessSnap);
EI>         return wxEmptyString;
EI>     }
EI>     wxZeroMemory(pe);
EI>     pe.dwSize = sizeof(PROCESSENTRY32);
EI>     cont = lpfProcess32Next (hProcessSnap, &pe) ? true : false;
EI> }

EI> The problem is that I manage to find my process ID, but I cant seem to
EI> properly convert the string (located at pe.szExeFile) I tried debugging it
EI> with gdb / VC debugger, both failed to display the string properly.

EI> Anyone experienced with such problem?

return wxString(pe.szExeFile);

should work just fine.

Eric





More information about the wx-users mailing list