🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
2 messages
2 total messages Started by Mike Collins Tue, 18 Sep 2007 21:36
using QueryDosDevice()
#1339
Author: Mike Collins
Date: Tue, 18 Sep 2007 21:36
24 lines
1849 bytes
Hi all, trying to use QueryDosDevice() to return a list of all Symbolic 
names and the Logical device that they correlate too.

DWORD QueryDosDevice(

    LPCTSTR lpDeviceName, // address of MS-DOS device name string
    LPTSTR lpTargetPath, // address of buffer for storing query results
    DWORD ucchMax  // maximum storage capacity of buffer
   );

I'm trying to do this, initially by passing a NULL value for the 
lpDeviceName.  However, i'm struggling to find a way to determine that 
required size of the lpTargetPath.  If i pass a buffer that is too small, 
the function returns a 0 and GetLastError reports "The data area passed to a 
system call is too small".  However there seems to be no way to bet the size 
of the required buffer.  Usually, in API's, the size parameter is modified 
if the buffer is too small, but in this case there seems to be no way to 
determine the required buffer size.

Any suggestions?

Thanks in advance,

Mike C 
Re: using QueryDosDevice()
#1341
Author: Remy Lebeau (TeamB)
Date: Tue, 18 Sep 2007 22:00
54 lines
2428 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message
news:46f0344e@newsgroups.borland.com...

> However, i'm struggling to find a way to determine that
> required size of the lpTargetPath.

You have to allocate a buffer of an initial size and then call the function
in a loop, increasing the size when needed, until the buffer is eventually
large enough, or an error occurs.  For example:

    DWORD dwLen = 1024;
    LPTSTR lpBuffer = LocalAlloc(LPTR, dwLen);
    while( lpBuffer != NULL )
    {
        if( QueryDosDevice(NULL, lpBuffer, dwLen) )
        {
            // use lpBuffer as needed ...
            break;
        }

        if( GetLastError() != ERROR_INSUFFICIENT_BUFFER )
        {
            // as error occured...
            break;
        }

        dwLen += 1024;
        LPTSTR lpNewBuffer = LocalReAlloc(lpBuffer, dwLen, LPTR);
        if( lpNewBuffer == NULL )
        {
            // could not resize memory, original memory is still valid...
            break;
        }

        lpBuffer = lpNewBuffer;
    }

    if( lpBuffer )
        LocalFree(lpBuffer);

> However there seems to be no way to bet the size of the
> required buffer.

You have to increase the buffer by an arbitrary size of your own choosing.
The function will not tell you the size to use.

> Usually, in API's, the size parameter is modified if the buffer
> is too small

Not always.  There are a several API functions that don't.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads