🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1341

Re: using QueryDosDevice()

#1341
From: 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
Technical Details
Message-ID: <46f04ac0$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46f0344e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2fc1216e36a3f247
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <46f0344e@newsgroups.borland.com>
Subject: Re: using QueryDosDevice()
Date: Tue, 18 Sep 2007 15:00:47 -0700
Lines: 56
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.83.29.61
Message-ID: <46f04ac0$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1190152896 75.83.29.61 (18 Sep 2007 15:01:36 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail