Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
// Allocate some memory to get a list of all system devices.
// Start with a small size and dynamically give more space until we have enough room.
int returnSize = 0;
int maxSize = 100;
string allDevices = null;
IntPtr mem;
string [] retval = null;
while(returnSize == 0)
{
mem = Marshal.AllocHGlobal(maxSize);
if(mem != IntPtr.Zero)
{
// mem points to memory that needs freeing
try
{
returnSize = QueryDosDevice(null, mem, maxSize);
if(returnSize != 0)
{
allDevices = Marshal.PtrToStringAnsi(mem, returnSize);
retval = allDevices.Split('\0');
break; // not really needed, but makes it more clear...
}
else if(GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
maxSize *= 10;
}
else
{
Marshal.ThrowExceptionForHR(GetLastError());
}
}
finally
{
Marshal.FreeHGlobal(mem);
}
}
else
{
throw new OutOfMemoryException();
}
}
return retval;
}
Alternative Managed API:
Do you know one? Please contribute it!
The QueryDosDevice API
2/20/2022 5:48:15 AM - -66.61.25.155
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).