471,310 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

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

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.SystemBas icInformation,
ptrBuffer,
10000000,
out l);

MessageBox.Show(DRWin32APIClass.NtStatusToWin32Exc eption(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."

Aug 23 '08 #1
2 2861
>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?

It is (or was) a bug in the function implementation. Don't know which
OS version you're running, but it looks like they've fixed it in
Vista.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 5 '08 #2
Hi Matthias,

thanks for the reply. I use XP SP3 up2date and i cant
get it work, still cant get it work and it is really not
clear to me, why this fails,...

If you have any idea how i can fix this, please
let me know, or know an alternative to enumerate
all kernel objects on a system like mutants, mutexes,
etc,...

I could write a writer for this and use a user defined
IOCTL to move the data from Kernel to Userland,
but since this can be done, at least what i need here,
with User Mode Code, there is no need for a Driver
so far,...

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."
"Mattias Sjögren" <ma********************@mvps.orgschrieb im Newsbeitrag
news:eS**************@TK2MSFTNGP04.phx.gbl...
>
>>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?


It is (or was) a bug in the function implementation. Don't know which
OS version you're running, but it looks like they've fixed it in
Vista.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 6 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Paul Fairless | last post: by
1 post views Thread by Garfield | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.