Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » SysInfo - GetProcessName() - bug?
SysInfo - GetProcessName() - bug? [message #35874] Fri, 30 March 2012 10:01 Go to next message
borbek is currently offline  borbek
Messages: 31
Registered: November 2010
Location: Russia
Member
The function returns an uninitialized string if OpenProcess or EnumProcessModules return an error.

Perhaps a better way:

String GetProcessName(long processID)
{
	WCHAR szProcessName[MAX_PATH];
	String r="";
	
    // Get a handle to the process.
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);
    
    // Get the process name.
    if (hProcess != NULL) {
        HMODULE hMod;
        DWORD cbNeeded;

        if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
        {
            GetModuleBaseNameW(hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(WCHAR));
            r=FromSystemCharset(WString(szProcessName).ToString());
        }
        
     }

  CloseHandle(hProcess);
  return r;
}

[Updated on: Fri, 30 March 2012 10:06]

Report message to a moderator

Re: SysInfo - GetProcessName() - bug? [message #35881 is a reply to message #35874] Fri, 30 March 2012 21:29 Go to previous message
koldo is currently offline  koldo
Messages: 3268
Registered: August 2008
Senior Veteran
Thanks Borbek

Included Smile.


Best regards
IƱaki
Previous Topic: LineTracker using background repaint:
Next Topic: Little change in FormExample
Goto Forum:
  


Current Time: Thu Oct 21 06:42:55 CEST 2021

Total time taken to generate the page: 0.01019 seconds