GetLogicalDriveStrings() and char - Where am I doing wrongly












3














I want to search a file which may be present in any drives such as C:, D: etc. Using GetLogicalDriveStrings I can able to get the list of drives but when I add anything extra for the output, I am getting a null in the output prompt. Here is my code:



#include "StdAfx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>

// Buffer length
DWORD mydrives = 100;
// Buffer for drive string storage
char lpBuffer[100];
const char *extFile = "text.ext";

// You may want to try the wmain() version
int main(void)
{
DWORD test;
int i;
test = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);
if(test != 0)
{
printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d n", test, GetLastError());
printf("The logical drives of this machine are:n");
// Check up to 100 drives...
for(i = 0; i<100; i++)
printf("%c%s", lpBuffer[i],extFile);
printf("n");
}
else
printf("GetLogicalDriveStrings() is failed lor!!! Error code: %dn", GetLastError());
_getch();
return 0;
}


I want above output as C:text.ext D:text.ext ... rather I am getting text.ext only. I am using Microsoft Visual C++ 2010 Express










share|improve this question




















  • 2




    You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
    – Jonathan Potter
    Sep 2 '13 at 12:14


















3














I want to search a file which may be present in any drives such as C:, D: etc. Using GetLogicalDriveStrings I can able to get the list of drives but when I add anything extra for the output, I am getting a null in the output prompt. Here is my code:



#include "StdAfx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>

// Buffer length
DWORD mydrives = 100;
// Buffer for drive string storage
char lpBuffer[100];
const char *extFile = "text.ext";

// You may want to try the wmain() version
int main(void)
{
DWORD test;
int i;
test = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);
if(test != 0)
{
printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d n", test, GetLastError());
printf("The logical drives of this machine are:n");
// Check up to 100 drives...
for(i = 0; i<100; i++)
printf("%c%s", lpBuffer[i],extFile);
printf("n");
}
else
printf("GetLogicalDriveStrings() is failed lor!!! Error code: %dn", GetLastError());
_getch();
return 0;
}


I want above output as C:text.ext D:text.ext ... rather I am getting text.ext only. I am using Microsoft Visual C++ 2010 Express










share|improve this question




















  • 2




    You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
    – Jonathan Potter
    Sep 2 '13 at 12:14
















3












3








3







I want to search a file which may be present in any drives such as C:, D: etc. Using GetLogicalDriveStrings I can able to get the list of drives but when I add anything extra for the output, I am getting a null in the output prompt. Here is my code:



#include "StdAfx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>

// Buffer length
DWORD mydrives = 100;
// Buffer for drive string storage
char lpBuffer[100];
const char *extFile = "text.ext";

// You may want to try the wmain() version
int main(void)
{
DWORD test;
int i;
test = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);
if(test != 0)
{
printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d n", test, GetLastError());
printf("The logical drives of this machine are:n");
// Check up to 100 drives...
for(i = 0; i<100; i++)
printf("%c%s", lpBuffer[i],extFile);
printf("n");
}
else
printf("GetLogicalDriveStrings() is failed lor!!! Error code: %dn", GetLastError());
_getch();
return 0;
}


I want above output as C:text.ext D:text.ext ... rather I am getting text.ext only. I am using Microsoft Visual C++ 2010 Express










share|improve this question















I want to search a file which may be present in any drives such as C:, D: etc. Using GetLogicalDriveStrings I can able to get the list of drives but when I add anything extra for the output, I am getting a null in the output prompt. Here is my code:



#include "StdAfx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>

// Buffer length
DWORD mydrives = 100;
// Buffer for drive string storage
char lpBuffer[100];
const char *extFile = "text.ext";

// You may want to try the wmain() version
int main(void)
{
DWORD test;
int i;
test = GetLogicalDriveStrings(mydrives, (LPWSTR)lpBuffer);
if(test != 0)
{
printf("GetLogicalDriveStrings() return value: %d, Error (if any): %d n", test, GetLastError());
printf("The logical drives of this machine are:n");
// Check up to 100 drives...
for(i = 0; i<100; i++)
printf("%c%s", lpBuffer[i],extFile);
printf("n");
}
else
printf("GetLogicalDriveStrings() is failed lor!!! Error code: %dn", GetLastError());
_getch();
return 0;
}


I want above output as C:text.ext D:text.ext ... rather I am getting text.ext only. I am using Microsoft Visual C++ 2010 Express







c++ char msdn const-char






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 2 '13 at 12:16

























asked Sep 2 '13 at 12:09









highlander141

95311638




95311638








  • 2




    You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
    – Jonathan Potter
    Sep 2 '13 at 12:14
















  • 2




    You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
    – Jonathan Potter
    Sep 2 '13 at 12:14










2




2




You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
– Jonathan Potter
Sep 2 '13 at 12:14






You're assigning "text.ext" to extFile 100 times, and then printing a string consisting of lpBuffer[100] (which is past the end of the buffer) and something called datFile which doesn't appear anywhere else in your example. Please check your code more carefully before posting for help.
– Jonathan Potter
Sep 2 '13 at 12:14














4 Answers
4






active

oldest

votes


















5














GetLogicalDriveStrings() returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B and C in your machine. The returned string would look like this:



A:<nul>B:<nul>C:<nul><nul>



You can use the following code to iterate through the strings in the returned buffer and print each one in turn:



DWORD dwSize = MAX_PATH;
char szLogicalDrives[MAX_PATH] = {0};
DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

if (dwResult > 0 && dwResult <= MAX_PATH)
{
char* szSingleDrive = szLogicalDrives;
while(*szSingleDrive)
{
printf("Drive: %sn", szSingleDrive);

// get the next drive
szSingleDrive += strlen(szSingleDrive) + 1;
}
}


Note that the details of how the function works, including the example code that I shamelessly copied and pasted, can be found by reading the docs.






share|improve this answer





















  • Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
    – highlander141
    Sep 2 '13 at 12:34





















0














Did you mean to put the printf in the loop?


Currently, you set extFile 100 times (just to be sure?!)



   for(i = 0; i<100; i++)
extFile = "text.ext";


You meant to show all the drive letters in a loop:



   for(i = 0; i<100; i++)
{
extFile = "text.ext";
printf("%c%s", lpBuffer[i], extFile); //I guess you mean extFile here?
}





share|improve this answer





















  • Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
    – highlander141
    Sep 2 '13 at 12:23










  • See Jonathan's answer
    – doctorlove
    Sep 2 '13 at 12:26



















0














DWORD dwSize = MAX_PATH;
WCHAR szLogicalDrives[MAX_PATH] = { 0 };
DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);

CStringArray m_Drives;
m_Drives.RemoveAll();

if (dwResult > 0 && dwResult <= MAX_PATH)
{
WCHAR* szSingleDrive = szLogicalDrives;
while (*szSingleDrive)
{
UINT nDriveType = GetDriveType(szSingleDrive);
m_Drives.Add(CString(szSingleDrive, 2));

// get the next drive
szSingleDrive += wcslen(szSingleDrive) + 1;
}
}
return m_Drives;





share|improve this answer





























    0














    class DriveList {
    protected:

    LPTSTR m_driveList;
    DWORD m_driveCount;
    DWORD m_bufSize = 32 * sizeof(TCHAR);

    public:

    virtual ~DriveList() {
    free(m_driveList);
    }

    DriveList() {
    m_driveList = (LPTSTR)malloc(m_bufSize);
    }

    int getDriveCount() const {
    return m_driveCount;
    }

    TCHAR operator (const int index) const {
    return m_driveList[index];
    }

    void loadDriveList() {
    DWORD mask;
    if((mask = GetLogicalDrives()) == 0) {
    throw;
    }

    m_driveCount = 0;
    for(int x = 0; x <= 25; x++ ) {
    if(mask & 1) {
    m_driveList[m_driveCount] = TCHAR(65 + x);
    m_driveCount += 1;
    }
    mask >>= 1;
    }
    }
    };





    share|improve this answer























    • Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
      – Anh Pham
      Nov 19 '18 at 13:47











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18572944%2fgetlogicaldrivestrings-and-char-where-am-i-doing-wrongly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    GetLogicalDriveStrings() returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B and C in your machine. The returned string would look like this:



    A:<nul>B:<nul>C:<nul><nul>



    You can use the following code to iterate through the strings in the returned buffer and print each one in turn:



    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
    char* szSingleDrive = szLogicalDrives;
    while(*szSingleDrive)
    {
    printf("Drive: %sn", szSingleDrive);

    // get the next drive
    szSingleDrive += strlen(szSingleDrive) + 1;
    }
    }


    Note that the details of how the function works, including the example code that I shamelessly copied and pasted, can be found by reading the docs.






    share|improve this answer





















    • Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
      – highlander141
      Sep 2 '13 at 12:34


















    5














    GetLogicalDriveStrings() returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B and C in your machine. The returned string would look like this:



    A:<nul>B:<nul>C:<nul><nul>



    You can use the following code to iterate through the strings in the returned buffer and print each one in turn:



    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
    char* szSingleDrive = szLogicalDrives;
    while(*szSingleDrive)
    {
    printf("Drive: %sn", szSingleDrive);

    // get the next drive
    szSingleDrive += strlen(szSingleDrive) + 1;
    }
    }


    Note that the details of how the function works, including the example code that I shamelessly copied and pasted, can be found by reading the docs.






    share|improve this answer





















    • Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
      – highlander141
      Sep 2 '13 at 12:34
















    5












    5








    5






    GetLogicalDriveStrings() returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B and C in your machine. The returned string would look like this:



    A:<nul>B:<nul>C:<nul><nul>



    You can use the following code to iterate through the strings in the returned buffer and print each one in turn:



    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
    char* szSingleDrive = szLogicalDrives;
    while(*szSingleDrive)
    {
    printf("Drive: %sn", szSingleDrive);

    // get the next drive
    szSingleDrive += strlen(szSingleDrive) + 1;
    }
    }


    Note that the details of how the function works, including the example code that I shamelessly copied and pasted, can be found by reading the docs.






    share|improve this answer












    GetLogicalDriveStrings() returns a double-null terminated list of null-terminated strings. E.g., say you had drives A, B and C in your machine. The returned string would look like this:



    A:<nul>B:<nul>C:<nul><nul>



    You can use the following code to iterate through the strings in the returned buffer and print each one in turn:



    DWORD dwSize = MAX_PATH;
    char szLogicalDrives[MAX_PATH] = {0};
    DWORD dwResult = GetLogicalDriveStrings(dwSize,szLogicalDrives);

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
    char* szSingleDrive = szLogicalDrives;
    while(*szSingleDrive)
    {
    printf("Drive: %sn", szSingleDrive);

    // get the next drive
    szSingleDrive += strlen(szSingleDrive) + 1;
    }
    }


    Note that the details of how the function works, including the example code that I shamelessly copied and pasted, can be found by reading the docs.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 2 '13 at 12:23









    Jonathan Potter

    30.6k43856




    30.6k43856












    • Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
      – highlander141
      Sep 2 '13 at 12:34




















    • Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
      – highlander141
      Sep 2 '13 at 12:34


















    Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
    – highlander141
    Sep 2 '13 at 12:34






    Hmm.. thanks :) Just to properly run, set in Project Properties Unicode to Not Set
    – highlander141
    Sep 2 '13 at 12:34















    0














    Did you mean to put the printf in the loop?


    Currently, you set extFile 100 times (just to be sure?!)



       for(i = 0; i<100; i++)
    extFile = "text.ext";


    You meant to show all the drive letters in a loop:



       for(i = 0; i<100; i++)
    {
    extFile = "text.ext";
    printf("%c%s", lpBuffer[i], extFile); //I guess you mean extFile here?
    }





    share|improve this answer





















    • Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
      – highlander141
      Sep 2 '13 at 12:23










    • See Jonathan's answer
      – doctorlove
      Sep 2 '13 at 12:26
















    0














    Did you mean to put the printf in the loop?


    Currently, you set extFile 100 times (just to be sure?!)



       for(i = 0; i<100; i++)
    extFile = "text.ext";


    You meant to show all the drive letters in a loop:



       for(i = 0; i<100; i++)
    {
    extFile = "text.ext";
    printf("%c%s", lpBuffer[i], extFile); //I guess you mean extFile here?
    }





    share|improve this answer





















    • Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
      – highlander141
      Sep 2 '13 at 12:23










    • See Jonathan's answer
      – doctorlove
      Sep 2 '13 at 12:26














    0












    0








    0






    Did you mean to put the printf in the loop?


    Currently, you set extFile 100 times (just to be sure?!)



       for(i = 0; i<100; i++)
    extFile = "text.ext";


    You meant to show all the drive letters in a loop:



       for(i = 0; i<100; i++)
    {
    extFile = "text.ext";
    printf("%c%s", lpBuffer[i], extFile); //I guess you mean extFile here?
    }





    share|improve this answer












    Did you mean to put the printf in the loop?


    Currently, you set extFile 100 times (just to be sure?!)



       for(i = 0; i<100; i++)
    extFile = "text.ext";


    You meant to show all the drive letters in a loop:



       for(i = 0; i<100; i++)
    {
    extFile = "text.ext";
    printf("%c%s", lpBuffer[i], extFile); //I guess you mean extFile here?
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 2 '13 at 12:17









    doctorlove

    14.5k22951




    14.5k22951












    • Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
      – highlander141
      Sep 2 '13 at 12:23










    • See Jonathan's answer
      – doctorlove
      Sep 2 '13 at 12:26


















    • Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
      – highlander141
      Sep 2 '13 at 12:23










    • See Jonathan's answer
      – doctorlove
      Sep 2 '13 at 12:26
















    Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
    – highlander141
    Sep 2 '13 at 12:23




    Well, yes I want the output as C:text.ext ... upto nth drive:text.ext. I've modified my code a little bit please check...
    – highlander141
    Sep 2 '13 at 12:23












    See Jonathan's answer
    – doctorlove
    Sep 2 '13 at 12:26




    See Jonathan's answer
    – doctorlove
    Sep 2 '13 at 12:26











    0














    DWORD dwSize = MAX_PATH;
    WCHAR szLogicalDrives[MAX_PATH] = { 0 };
    DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);

    CStringArray m_Drives;
    m_Drives.RemoveAll();

    if (dwResult > 0 && dwResult <= MAX_PATH)
    {
    WCHAR* szSingleDrive = szLogicalDrives;
    while (*szSingleDrive)
    {
    UINT nDriveType = GetDriveType(szSingleDrive);
    m_Drives.Add(CString(szSingleDrive, 2));

    // get the next drive
    szSingleDrive += wcslen(szSingleDrive) + 1;
    }
    }
    return m_Drives;





    share|improve this answer


























      0














      DWORD dwSize = MAX_PATH;
      WCHAR szLogicalDrives[MAX_PATH] = { 0 };
      DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);

      CStringArray m_Drives;
      m_Drives.RemoveAll();

      if (dwResult > 0 && dwResult <= MAX_PATH)
      {
      WCHAR* szSingleDrive = szLogicalDrives;
      while (*szSingleDrive)
      {
      UINT nDriveType = GetDriveType(szSingleDrive);
      m_Drives.Add(CString(szSingleDrive, 2));

      // get the next drive
      szSingleDrive += wcslen(szSingleDrive) + 1;
      }
      }
      return m_Drives;





      share|improve this answer
























        0












        0








        0






        DWORD dwSize = MAX_PATH;
        WCHAR szLogicalDrives[MAX_PATH] = { 0 };
        DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);

        CStringArray m_Drives;
        m_Drives.RemoveAll();

        if (dwResult > 0 && dwResult <= MAX_PATH)
        {
        WCHAR* szSingleDrive = szLogicalDrives;
        while (*szSingleDrive)
        {
        UINT nDriveType = GetDriveType(szSingleDrive);
        m_Drives.Add(CString(szSingleDrive, 2));

        // get the next drive
        szSingleDrive += wcslen(szSingleDrive) + 1;
        }
        }
        return m_Drives;





        share|improve this answer












        DWORD dwSize = MAX_PATH;
        WCHAR szLogicalDrives[MAX_PATH] = { 0 };
        DWORD dwResult = GetLogicalDriveStrings(dwSize, szLogicalDrives);

        CStringArray m_Drives;
        m_Drives.RemoveAll();

        if (dwResult > 0 && dwResult <= MAX_PATH)
        {
        WCHAR* szSingleDrive = szLogicalDrives;
        while (*szSingleDrive)
        {
        UINT nDriveType = GetDriveType(szSingleDrive);
        m_Drives.Add(CString(szSingleDrive, 2));

        // get the next drive
        szSingleDrive += wcslen(szSingleDrive) + 1;
        }
        }
        return m_Drives;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 1 '15 at 21:15









        Michael Haephrati

        1,4781528




        1,4781528























            0














            class DriveList {
            protected:

            LPTSTR m_driveList;
            DWORD m_driveCount;
            DWORD m_bufSize = 32 * sizeof(TCHAR);

            public:

            virtual ~DriveList() {
            free(m_driveList);
            }

            DriveList() {
            m_driveList = (LPTSTR)malloc(m_bufSize);
            }

            int getDriveCount() const {
            return m_driveCount;
            }

            TCHAR operator (const int index) const {
            return m_driveList[index];
            }

            void loadDriveList() {
            DWORD mask;
            if((mask = GetLogicalDrives()) == 0) {
            throw;
            }

            m_driveCount = 0;
            for(int x = 0; x <= 25; x++ ) {
            if(mask & 1) {
            m_driveList[m_driveCount] = TCHAR(65 + x);
            m_driveCount += 1;
            }
            mask >>= 1;
            }
            }
            };





            share|improve this answer























            • Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
              – Anh Pham
              Nov 19 '18 at 13:47
















            0














            class DriveList {
            protected:

            LPTSTR m_driveList;
            DWORD m_driveCount;
            DWORD m_bufSize = 32 * sizeof(TCHAR);

            public:

            virtual ~DriveList() {
            free(m_driveList);
            }

            DriveList() {
            m_driveList = (LPTSTR)malloc(m_bufSize);
            }

            int getDriveCount() const {
            return m_driveCount;
            }

            TCHAR operator (const int index) const {
            return m_driveList[index];
            }

            void loadDriveList() {
            DWORD mask;
            if((mask = GetLogicalDrives()) == 0) {
            throw;
            }

            m_driveCount = 0;
            for(int x = 0; x <= 25; x++ ) {
            if(mask & 1) {
            m_driveList[m_driveCount] = TCHAR(65 + x);
            m_driveCount += 1;
            }
            mask >>= 1;
            }
            }
            };





            share|improve this answer























            • Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
              – Anh Pham
              Nov 19 '18 at 13:47














            0












            0








            0






            class DriveList {
            protected:

            LPTSTR m_driveList;
            DWORD m_driveCount;
            DWORD m_bufSize = 32 * sizeof(TCHAR);

            public:

            virtual ~DriveList() {
            free(m_driveList);
            }

            DriveList() {
            m_driveList = (LPTSTR)malloc(m_bufSize);
            }

            int getDriveCount() const {
            return m_driveCount;
            }

            TCHAR operator (const int index) const {
            return m_driveList[index];
            }

            void loadDriveList() {
            DWORD mask;
            if((mask = GetLogicalDrives()) == 0) {
            throw;
            }

            m_driveCount = 0;
            for(int x = 0; x <= 25; x++ ) {
            if(mask & 1) {
            m_driveList[m_driveCount] = TCHAR(65 + x);
            m_driveCount += 1;
            }
            mask >>= 1;
            }
            }
            };





            share|improve this answer














            class DriveList {
            protected:

            LPTSTR m_driveList;
            DWORD m_driveCount;
            DWORD m_bufSize = 32 * sizeof(TCHAR);

            public:

            virtual ~DriveList() {
            free(m_driveList);
            }

            DriveList() {
            m_driveList = (LPTSTR)malloc(m_bufSize);
            }

            int getDriveCount() const {
            return m_driveCount;
            }

            TCHAR operator (const int index) const {
            return m_driveList[index];
            }

            void loadDriveList() {
            DWORD mask;
            if((mask = GetLogicalDrives()) == 0) {
            throw;
            }

            m_driveCount = 0;
            for(int x = 0; x <= 25; x++ ) {
            if(mask & 1) {
            m_driveList[m_driveCount] = TCHAR(65 + x);
            m_driveCount += 1;
            }
            mask >>= 1;
            }
            }
            };






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 19 '18 at 13:33

























            answered Nov 19 '18 at 13:27









            zep

            11




            11












            • Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
              – Anh Pham
              Nov 19 '18 at 13:47


















            • Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
              – Anh Pham
              Nov 19 '18 at 13:47
















            Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
            – Anh Pham
            Nov 19 '18 at 13:47




            Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read How do I write a good answer, and also Explaining entirely code-based answers
            – Anh Pham
            Nov 19 '18 at 13:47


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f18572944%2fgetlogicaldrivestrings-and-char-where-am-i-doing-wrongly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith