c++ - Using System::AnsiString class -
i trying import code following answer: get full running process list ( visual c++ )
bool findrunningprocess(ansistring process) { /* function takes in string value process looking st3monitor.exe loops through of processes running on windows. if process found running, therefore function returns true. */ ansistring compare; bool procrunning = false; handle hprocesssnap; processentry32 pe32; hprocesssnap = createtoolhelp32snapshot(th32cs_snapprocess, 0); if (hprocesssnap == invalid_handle_value) { procrunning = false; } else { pe32.dwsize = sizeof(processentry32); if (process32first(hprocesssnap, &pe32)) { // gets first running process if (pe32.szexefile == process) { procrunning = true; } else { // loop through running processes looking process while (process32next(hprocesssnap, &pe32)) { // set ansistring instead of char[] make compare easier compare = pe32.szexefile; if (compare == process) { // if found process running, set true , break loop procrunning = true; break; } } } // clean snapshot object closehandle(hprocesssnap); } }
in phil's answer, using system::ansistring
class , im not sure how can include in project, i.e. apart of installed packages or need download , include it?
an extension of question: there substitute can use achieve same thing ansistring?
my end goal code modify can current list of running processes , looking specific process terminate if running. tried using ce::string
, since pe32.szexefile
type tchar [260]
, unable pass ce::string
declaration of following ce::string process_name;
(which why using system::ansistring
).
i assume pe32.szexefile
going return process name, wanted compare declared string specific process name.
okay, so, it's not @ clear ansistring
is; you've assumed it's the embarcadero system::ansistring
class and, frankly, looks reasonable assumption.
i wouldn't go trying obtain it, though. i focus on writing standard code, switching std::string
/std::wstring
(as appropriate). should near-trivial adapt author's code portable. you'll have play around , read documentation functions used in code, see work , not. looks system::ansistring
or std::string
-compatible, won't know until try it.
i cannot stress enough how important do not go down road of stepping time machine , opening @ 1950, lunch box full of pointers , horridly antiquated c-string comparison functions. don't why suggest doing that.
Comments
Post a Comment