Click here to Skip to main content
15,890,506 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
QuestionRe: Directory Pin
David Crow6-Mar-06 2:48
David Crow6-Mar-06 2:48 
QuestionProblem with SQLSetEnvAttr Pin
Amit j Patil5-Mar-06 23:49
Amit j Patil5-Mar-06 23:49 
QuestionDeclare in form1.h causes error Pin
jantimmerman5-Mar-06 23:43
jantimmerman5-Mar-06 23:43 
AnswerRe: Declare in form1.h causes error Pin
Sebastian Schneider5-Mar-06 23:46
Sebastian Schneider5-Mar-06 23:46 
AnswerRe: Declare in form1.h causes error Pin
Ryan Binns5-Mar-06 23:57
Ryan Binns5-Mar-06 23:57 
GeneralRe: Declare in form1.h causes error Pin
jantimmerman6-Mar-06 1:14
jantimmerman6-Mar-06 1:14 
GeneralRe: Declare in form1.h causes error Pin
Ryan Binns6-Mar-06 3:10
Ryan Binns6-Mar-06 3:10 
QuestionVS 2005 manifest file problem. Pin
yourbuddy775-Mar-06 23:39
yourbuddy775-Mar-06 23:39 
QuestionConversion from VS 6.0 to .Net Pin
Neelesh K J Jain5-Mar-06 23:28
Neelesh K J Jain5-Mar-06 23:28 
AnswerRe: Conversion from VS 6.0 to .Net Pin
Nibu babu thomas5-Mar-06 23:36
Nibu babu thomas5-Mar-06 23:36 
AnswerRe: Conversion from VS 6.0 to .Net Pin
Christian Graus6-Mar-06 1:04
protectorChristian Graus6-Mar-06 1:04 
QuestionPower of 2 Pin
RichardS5-Mar-06 23:23
RichardS5-Mar-06 23:23 
Answer[Removed] Pin
toxcct5-Mar-06 23:28
toxcct5-Mar-06 23:28 
GeneralRe: Power of 2 Pin
RichardS5-Mar-06 23:34
RichardS5-Mar-06 23:34 
GeneralRe: Power of 2 Pin
Cedric Moonen5-Mar-06 23:44
Cedric Moonen5-Mar-06 23:44 
GeneralRe: Power of 2 Pin
toxcct5-Mar-06 23:46
toxcct5-Mar-06 23:46 

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.