Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

(c++) simpe output

Featured Replies

Posted

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

:unsure:

Edited by deepzero

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...

  • Author

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.:hug:

edit:

any idea, though, how to print the output into a variable?

Edited by deepzero

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).

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.:hug:

edit:

any idea, though, how to print the output into a variable?

Use wsprintf and probably wcscat.

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.