Solved

GetLogicalDriveString

Posted on 2000-05-06
9
424 Views
Last Modified: 2013-12-03
Would someone be kind enough to properly translate the following into C for me (I cant program MFC) - I've tried bu keep making a mess of it <s>

      DWORD Check;
    char buffer[30];
      CStringArray l_saDrives;
    char chTemp[10];
      int Count = 0;

      Check=GetLogicalDriveStrings(20,buffer);

      ZeroMemory(chTemp, 10);

      for(int i = 0; i < Check; i++)
      {
            if(buffer[i] == 0)
            {
             l_saDrives.Add(chTemp);
             ZeroMemory(chTemp, 10);
             Count = 0;
            }
            else
            chTemp[Count++] = buffer[i];

      }
     
      for(i = 0; i < l_saDrives.GetSize(); i++)
      {
      AfxMessageBox(l_saDrives[i]);
      }

DarrinE
0
Comment
Question by:DarrinE
  • 5
  • 4
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 2783899
     char acBuffer [ 256];
      BOOL bRet;
      int  i = 0;

      char* pc;
      char* apszDrives [ 27];

      ZeroMemory ( acBuffer, sizeof ( acBuffer));
      ZeroMemory ( apszDrives, sizeof ( apszDrives));

      bRet = GetLogicalDriveStrings ( 256, acBuffer);

      pc = acBuffer;

      while ( *pc)
      {
            apszDrives [ i++] = pc;

            pc = memchr ( pc + 1, '\0', 256);

            if ( !pc) break;

            pc++;
      }

This will place all drive strings in the pointer array 'apszDrives'
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2783967
Thanks jkr - finishing with this for an A grade answer

for(i = 0; i < l_saDrives.GetSize(); i++)
{
AfxMessageBox(l_saDrives[i]);
}

DarrinE
0
 
LVL 86

Expert Comment

by:jkr
ID: 2784040
Ooops, have overseen this ;-)

i = 0;
for ( ;;)
{
      if ( !apszDrives [ i]) break;
      MessageBox ( NULL, apszDrives [ i++], "Drive found", MB_OK | MB_ICONINFORMATION);
}      
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Author Comment

by:DarrinE
ID: 2784743
I am greatful for the prompt response - I have not tried it - but it looks fine - tell me how can I tell the maximum size of apszDrives [ i]

Many thanks

DarrinE
0
 
LVL 86

Expert Comment

by:jkr
ID: 2784893
The maximum size is (should always) be 26 - there aren't any more letters in the alphabet ;-)
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2784895
OK - I get it - but how can I tell how many arrays are in apszDrives ?
0
 
LVL 86

Expert Comment

by:jkr
ID: 2785584
while ( *pc)
{
apszDrives [ i++] = pc;

pc = memchr ( pc + 1, '\0', 256);

if ( !pc) break;

pc++;
}

When the loop is finished, 'i' holds the number of drives...
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2785610
Many thanks

Have a good one <!>

Send me a private email and I'll send you a fix for the loveletter virus I've just finished - does not do the server - just the local PC

dwe@primus.com.au
0
 
LVL 86

Expert Comment

by:jkr
ID: 2785988
Not needed - our sendmail gateway (Linux) simply kicks all of them ;-)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question