Click here to Skip to main content
15,914,287 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionList Box Pin
J51219826-Mar-06 1:20
J51219826-Mar-06 1:20 
AnswerRe: List Box Pin
Hamid_RT6-Mar-06 1:29
Hamid_RT6-Mar-06 1:29 
GeneralRe: List Box Pin
toxcct6-Mar-06 1:56
toxcct6-Mar-06 1:56 
AnswerRe: List Box Pin
Stephen Hewitt6-Mar-06 1:49
Stephen Hewitt6-Mar-06 1:49 
AnswerRe: List Box Pin
gamitech6-Mar-06 2:12
gamitech6-Mar-06 2:12 
QuestionHow to create Web Setup package Pin
mahammadhusen6-Mar-06 1:10
mahammadhusen6-Mar-06 1:10 
QuestionChanging the color of dialog box Pin
Aryan S6-Mar-06 1:06
Aryan S6-Mar-06 1:06 
AnswerRe: Changing the color of dialog box Pin
Nibu babu thomas6-Mar-06 1:11
Nibu babu thomas6-Mar-06 1:11 
QuestionRe: Changing the color of dialog box Pin
Aryan S6-Mar-06 1:49
Aryan S6-Mar-06 1:49 
AnswerRe: Changing the color of dialog box Pin
Eytukan6-Mar-06 2:51
Eytukan6-Mar-06 2:51 
AnswerRe: Changing the color of dialog box Pin
Hamid_RT6-Mar-06 1:12
Hamid_RT6-Mar-06 1:12 
GeneralRe: Changing the color of dialog box Pin
Aryan S6-Mar-06 1:46
Aryan S6-Mar-06 1:46 
GeneralRe: Changing the color of dialog box Pin
Hamid_RT6-Mar-06 2:52
Hamid_RT6-Mar-06 2:52 
AnswerRe: Changing the color of dialog box Pin
J51219826-Mar-06 1:23
J51219826-Mar-06 1:23 
GeneralRe: Changing the color of dialog box Pin
rajeev826-Mar-06 2:01
rajeev826-Mar-06 2:01 
QuestionREceive events in serial comms Pin
Trollslayer6-Mar-06 0:55
mentorTrollslayer6-Mar-06 0:55 
AnswerRe: REceive events in serial comms Pin
kakan6-Mar-06 1:39
professionalkakan6-Mar-06 1:39 
GeneralRe: REceive events in serial comms Pin
Trollslayer6-Mar-06 1:54
mentorTrollslayer6-Mar-06 1:54 
GeneralRe: REceive events in serial comms Pin
kakan6-Mar-06 2:38
professionalkakan6-Mar-06 2:38 
AnswerRe: REceive events in serial comms Pin
Roger Stoltz6-Mar-06 1:54
Roger Stoltz6-Mar-06 1:54 
GeneralRe: REceive events in serial comms Pin
Trollslayer6-Mar-06 1:57
mentorTrollslayer6-Mar-06 1:57 
Questionplease read it is importent Pin
baldha rakesh6-Mar-06 0:47
baldha rakesh6-Mar-06 0:47 
AnswerRe: please read it is importent Pin
Christian Graus6-Mar-06 1:03
protectorChristian Graus6-Mar-06 1:03 
Questionproblem using NtQuerySystemInformation Pin
gamitech6-Mar-06 0:19
gamitech6-Mar-06 0:19 
So I want to enumerate the processes using NtQuerySystemInformation() native api.
I load it from ntdll.dll
i use the process structure below unlike the one documented by microsoft. but i've seen that others use it too.

typedef struct _SYSTEM_PROCESS_INFORMATION
{
DWORD dNext;
DWORD dThreadCount;
DWORD dReserved01;
DWORD dReserved02;
DWORD dReserved03;
DWORD dReserved04;
DWORD dReserved05;
DWORD dReserved06;
QWORD qCreateTime;
QWORD qUserTime;
QWORD qKernelTime;
UNICODE_STRING usName;
DWORD BasePriority;
DWORD dUniqueProcessId;
DWORD dInheritedFromUniqueProcessId;
DWORD dHandleCount;
DWORD dReserved07;
DWORD dReserved08;
VM_COUNTERS VmCounters;
DWORD dCommitCharge;
SYSTEM_THREAD Threads[1];
} SYSTEM_PROCESS_INFORMATION;

the thing is that when I call it I don't get any error code or null pointers but the structure's members are zeros.
the dNext member is not zero but I can't obtain the next pointer for another system_process_information because i get the invalid pointer error when I try this:

if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);



And I have another question.
How much space should I allocate for the ProcessInfo structure
i only allocate for one structure
SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION));

or I shouldn't allocate at all. I will obtain a pointer to the structure anyway ?
here is the code I use:


HMODULE ntHinst;

ntHinst=LoadLibraryA(NTDLL);
if (ntHinst==NULL)
{
MessageBoxA(GetDesktopWindow(),"Error loading ntdll\nThe program will now end","ERROR",MB_ICONSTOP);
return 0;
}

_NtQuerySystemInformation=(NTQUERYSYSTEMINFORMATION)GetProcAddress(ntHinst,"NtQuerySystemInformation");
if(!_NtQuerySystemInformation)
{
MessageBoxA(GetDesktopWindow(),"Error obtaining function pointer\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}


SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION);
if (IsBadReadPtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION))||IsBadWritePtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION)))
return 0;

_NtQuerySystemInformation(SystemProcessInformation ,(PVOID)ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION),&ret);

if (ret==0)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}
if(ProcessInfo==NULL)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}

while(ProcessInfo!=NULL)
{
//RtlUnicodeStringToOemString(usname,&ProcessInfo->usName,TRUE);
//MessageBoxA(0,usname->Buffer,"",MB_OK);
//RtlFreeOemString(usname);

HANDLE hProc;
hProc=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ProcessInfo->dUniqueProcessId);
if (hProc!=NULL)
{
HMODULE hmods[300];
DWORD retv;
char fname[1024];

EnumProcessModules(hProc,hmods,sizeof(hmods),&retv);
retv=retv/sizeof(DWORD);
GetModuleFileNameA(*hmods,fname,sizeof(fname));
MessageBoxA(GetDesktopWindow(),fname,"Process Name",MB_OK);
}
else if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;

if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;

}

free(ProcessInfo);

So I get no errors durin calling. but I also get a structure full of zero's.
What is the pb ?

gabby
QuestionDirectory Pin
sundar_mca6-Mar-06 0:17
sundar_mca6-Mar-06 0:17 

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.