Thread: re-post garbled output: GetLogical DriveStrings

  1. #1

    re-post garbled output: GetLogical DriveStrings

    why do i get garbled output from this:

    BOOL getLogicalNames(char *psDriveBuffer, DWORD nBufLen)
    DWORD nRes;
    printf("Getting Logical Names\n");

    if ( (nRes = GetLogicalDriveStrings (nBufLen, psDriveBuffer) )== 0 )
    return FALSE;
    printf("%d, %s", nRes, psDriveBuffer);
    return TRUE;

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    psDriveBuffer has to be an array, orelse you'll get an "access violation".
    Try it this way:

    char psDriveBuffer[256]; //modify array size as you need
    DWORD nBufLen;

    DWORD nRes;
    nBufLen = 256;
    printf("Getting Logical Names\n");

    nRes = GetLogicalDriveStrings (nBufLen, &psDriveBuffer[0]);


    Have a nice code!

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    DWORD GetLogicalDriveStrings(
    DWORD nBufferLength, // size of buffer
    LPTSTR lpBuffer // pointer to buffer for drive strings

    Specifies the maximum size, in characters, of the buffer pointed to by lpBuffer. This size does not include the terminating null character.

    Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with <null> representing the terminating null character.

    If you set the two parameters accordingly, i.e. allocated space
    for the char* and wrote the size of the allocated space to
    your dword, I don't see why you shouldn't get the first
    logical drive. You won't get all, though with your method
    of printing, because printf will go for zero terminated strings,
    and your output has zeros in it that are not meant to be
    the end of the output, just the end of one string.

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    To list the drives with printf (as each entry is 4 bytes long e.g. A:\terminating_zero) try this:

    #define MAX_DRIVE_NO 24

    char psDriveBuffer[MAX_DRIVE_NO][4];
    GetLogicalDriveStrings (nBufLen, &psDriveBuffer[0][0]);

    for ( int i = 0; i <= MAX_DRIVE_NO, i++ )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why this output?
    By dredre in forum C Programming
    Replies: 4
    Last Post: 05-08-2004, 04:09 PM
  2. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  3. Control different DA output value!
    By Hunterhunter in forum A Brief History of
    Replies: 1
    Last Post: 03-13-2003, 12:11 PM
  4. garbled output: Win32 : GetLogicalDriveStrings()
    By richgi in forum Windows Programming
    Replies: 2
    Last Post: 10-10-2001, 02:15 AM
  5. To all who read last post formatted output
    By spliff in forum C Programming
    Replies: 8
    Last Post: 08-21-2001, 03:37 AM