deepzero Posted October 8, 2010 Posted October 8, 2010 (edited) hi, this program is supposed to output the pids & names of all running processes: PROCESSENTRY32 pe32;HANDLE procsnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );pe32.dwSize = sizeof(PROCESSENTRY32);Process32First(procsnap, &pe32);while(Process32Next(procsnap, &pe32)){printf( "PID: %d [%s]\n", pe32.th32ProcessID, pe32.szExeFile);} However, only the first char of the process name is printed. The PROCESSENTRY32 structure can be found here:/>http://msdn.microsoft.com/en-us/library/ms684839%28v=VS.85%29.aspx Edited October 8, 2010 by deepzero
Aguila Posted October 8, 2010 Posted October 8, 2010 there is a UNICODE and ANSI version of Process32First and Process32Next. You are using the UNICODE version...solution:use wprintf, change project to multi byte, convert wchar[] to char[], some more...
deepzero Posted October 8, 2010 Author Posted October 8, 2010 (edited) yes, you´re absolutely right. looking at the definitions: #define Process32First Process32FirstW (then why offer a Process32First in the first place?) So i can just use wprintf: while(Process32Next(procsnap, &pe32)){//cout << (char *) pe32.szExeFile << endl; ::wprintf(L"PID: %d [ %s ]\n", pe32.th32ProcessID, pe32.szExeFile);} And now it works. Big thx. edit: any idea, though, how to print the output into a variable? Edited October 8, 2010 by deepzero
Aguila Posted October 8, 2010 Posted October 8, 2010 I guess this is a mistake by microsoft developers. Normally you can easily choose the ANSI or UNICODE version of an api by adding an A or a W at the end of the name. Process32Next/Process32First is the sole exception (at least I dont know any other).
Hyperlisk Posted October 8, 2010 Posted October 8, 2010 yes, you´re absolutely right. looking at the definitions: #define Process32First Process32FirstW (then why offer a Process32First in the first place?) So i can just use wprintf: while(Process32Next(procsnap, &pe32)){//cout << (char *) pe32.szExeFile << endl; ::wprintf(L"PID: %d [ %s ]\n", pe32.th32ProcessID, pe32.szExeFile);} And now it works. Big thx. edit: any idea, though, how to print the output into a variable? Use wsprintf and probably wcscat.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now