Click here to Skip to main content
16,005,682 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: It is working! Thanks Pin
ATC9-Aug-02 6:29
ATC9-Aug-02 6:29 
GeneralDataBase variables Pin
RuiSantiago9-Aug-02 4:15
RuiSantiago9-Aug-02 4:15 
GeneralRe: DataBase variables Pin
nlecren9-Aug-02 5:32
nlecren9-Aug-02 5:32 
GeneralRe: DataBase variables Pin
RuiSantiago9-Aug-02 5:35
RuiSantiago9-Aug-02 5:35 
GeneralWindows and Programs Pin
Slayders9-Aug-02 4:07
Slayders9-Aug-02 4:07 
GeneralRe: Windows and Programs Pin
David Viggiano9-Aug-02 4:17
David Viggiano9-Aug-02 4:17 
GeneralRe: Windows and Programs Pin
Slayders9-Aug-02 4:27
Slayders9-Aug-02 4:27 
GeneralRe: Windows and Programs Pin
David Viggiano9-Aug-02 4:35
David Viggiano9-Aug-02 4:35 
Yea it is. Getting the PID is not the problem, as you can see. Getting the process name from the PID is difficult.

But there is an easier solution if PSAPI.DLL is installed. By default it is there on W2K and XP, redistributable for NT is available. No support for 95/98/Me. Here is how I use it:

In my constructor I have something like

HINSTANCE hInst;

m_pfGetModuleBaseName = NULL;
m_pfEnumProcessModules = NULL;

hInst = LoadLibrary (_T("psapi.dll"));
if (hInst != NULL)
{
m_pfGetModuleBaseName = (GETMODULEBASENAME) GetProcAddress (hInst, _T("GetModuleBaseNameA"));
m_pfEnumProcessModules = (ENUMPROCESSMODULES)GetProcAddress (hInst, _T("EnumProcessModules"));
FreeLibrary (hInst);
}
}


Then I use it as follows

HANDLE hProc;
HMODULE ahMod[10];
DWORD dwNeeded;
BOOL bStatus = FALSE;
char szProcessName[80];

rStrProcessName = "";

if (m_pfEnumProcessModules == NULL || m_pfGetModuleBaseName == NULL)
return (FALSE);

// Need to get a handle to the process so we can query the modules
hProc = OpenProcess (PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, dwPID);
if (hProc)
{
// Get the first few modules. The .exe is always the first one.
if (m_pfEnumProcessModules (hProc, ahMod, sizeof(ahMod), &dwNeeded))
{
// Get the exe name. It is always the first module.
if (m_pfGetModuleBaseName (hProc, ahMod[0], szProcessName, sizeof(szProcessName)))
{
rStrProcessName = szProcessName;
bStatus = TRUE;
}
}
CloseHandle (hProc);
}
return (bStatus);
}

GeneralRe: Windows and Programs Pin
Slayders9-Aug-02 5:16
Slayders9-Aug-02 5:16 
GeneralRe: Windows and Programs Pin
David Viggiano9-Aug-02 5:28
David Viggiano9-Aug-02 5:28 
GeneralRe: Windows and Programs Pin
Slayders9-Aug-02 5:38
Slayders9-Aug-02 5:38 
GeneralRe: Windows and Programs Pin
David Viggiano9-Aug-02 5:50
David Viggiano9-Aug-02 5:50 
GeneralRe: Windows and Programs Pin
Slayders9-Aug-02 6:03
Slayders9-Aug-02 6:03 
GeneralRe: Windows and Programs Pin
Slayders27-Aug-02 23:57
Slayders27-Aug-02 23:57 
QuestionHow create a DSN File at run time? Pin
Tomas9-Aug-02 4:00
Tomas9-Aug-02 4:00 
GeneralWhat's the easier way to debug COM Reference Counting Pin
Anonymous9-Aug-02 2:22
Anonymous9-Aug-02 2:22 
GeneralRe: What's the easier way to debug COM Reference Counting Pin
Chris Losinger9-Aug-02 3:31
professionalChris Losinger9-Aug-02 3:31 
GeneralMFC 6.0/7.0 compatibility Pin
Patrick REY9-Aug-02 2:22
Patrick REY9-Aug-02 2:22 
GeneralRe: MFC 6.0/7.0 compatibility Pin
Jim A. Johnson9-Aug-02 3:09
Jim A. Johnson9-Aug-02 3:09 
GeneralReleaseMutex Pin
slah9-Aug-02 1:57
slah9-Aug-02 1:57 
GeneralRe: ReleaseMutex Pin
Simon.W9-Aug-02 2:22
Simon.W9-Aug-02 2:22 
GeneralRe: ReleaseMutex Pin
Tim Smith9-Aug-02 2:23
Tim Smith9-Aug-02 2:23 
GeneralVersions of applications (VS_VERSION_INFO) Pin
klm9-Aug-02 1:35
klm9-Aug-02 1:35 
GeneralRe: Versions of applications (VS_VERSION_INFO) Pin
Tim Smith9-Aug-02 2:26
Tim Smith9-Aug-02 2:26 
GeneralRe: Versions of applications (VS_VERSION_INFO) Pin
klm9-Aug-02 2:30
klm9-Aug-02 2:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.