Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Parameter "ReturnLength" always "0" when NtQuerySystemInformation is called,...

22 views
Skip to first unread message

Kerem Gümrükcü

unread,
Aug 23, 2008, 4:11:39 PM8/23/08
to
Hi,

the topic says all. I use this code from C# to call the
NtQuerySystemInformation.
When i call NtQuerySystemInformation the first time with zero buffer length
to
get the buffer size needed for the information i get a
STATUS_INFO_LENGTH_MISMATCH
which is -1073741820 in number, this is ok, but why does the function not
store the required
buffer size in "ReturnLength"? Its always zero,...why? Is something wrong
with my declaration:

[DllImport("ntdll.dll",
EntryPoint = "NtQuerySystemInformation",
SetLastError = true,
CharSet = CharSet.Unicode,
ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)]
public static extern int NtQuerySystemInformation(
SYSTEM_INFORMATION_CLASS SystemInformationClass,
IntPtr SystemInformation,
uint SystemInformationLength,
out uint ReturnLength);

uint l = 0;
IntPtr ptrBuffer = Marshal.AllocHGlobal(10000000); //just some "buffer"
space, not used
int err = DRWin32APIClass.NtQuerySystemInformation(
DRWin32APIClass.SYSTEM_INFORMATION_CLASS.SystemBasicInformation,
ptrBuffer,
10000000,
out l);

MessageBox.Show(DRWin32APIClass.NtStatusToWin32Exception(err).Message + "\n"
+ err.ToString() + "\n" + l.ToString());

Marshal.FreeHGlobal(ptrBuffer);

The "ReturnLength" is always zero (0),...very strange. I am doing something
wrong here,...

I know that i can use for this class the Win32 API GetSystemInfo(...), but
the
call fails on any class, no matter if i want some Handles/Objects, etc
Information,...


Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

Kerem Gümrükcü

unread,
Aug 23, 2008, 5:06:52 PM8/23/08
to

dominique

unread,
Aug 24, 2008, 6:29:10 AM8/24/08
to
Kerem Gümrükcü wrote:
> Hi,
>
> the topic says all. I use this code from C# to call the
> NtQuerySystemInformation.
> When i call NtQuerySystemInformation the first time with zero buffer
> length to
> get the buffer size needed for the information i get a
> STATUS_INFO_LENGTH_MISMATCH
> which is -1073741820 in number, this is ok, but why does the function
> not store the required
> buffer size in "ReturnLength"? Its always zero,...why? Is something
> wrong with my declaration:

Have you compared with others working samples ?
like http://archive.sadeveloper.net/Forums/PostAttachment.aspx?PostID=73987

Kerem Gümrükcü

unread,
Aug 27, 2008, 1:00:16 AM8/27/08
to
Hi Dominique,

for whatever reason, i still get ZERO as NeededSize
on the OUT Parameter...i am really confused!

Using this is,...useless:

[DllImport("ntdll.dll",
EntryPoint = "NtQuerySystemInformation",
SetLastError = true,
CharSet = CharSet.Unicode,
ExactSpelling = true,
CallingConvention = CallingConvention.Winapi)]
public static extern int NtQuerySystemInformation(

[In] SYSTEM_INFORMATION_CLASS SystemInformationClass,
[In] IntPtr SystemInformation,
[In] uint SystemInformationLength,
[Out] out uint ReturnLength);

"ReturnLength" is always ZERO!

System is Windows XP SP3

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.codeplex.com/restarts
Latest Open-Source Projects: http://entwicklung.junetz.de
-----------------------
"This reply is provided as is, without warranty express or implied."

"dominique" <domi...@domi.com> schrieb im Newsbeitrag
news:g8rd9d$q44$1...@news.albasani.net...

0 new messages