Solved

GetLogicalDriveString

Posted on 2000-05-06
9
422 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
Comment Utility
     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
Comment Utility
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
Comment Utility
Ooops, have overseen this ;-)

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

Author Comment

by:DarrinE
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 86

Expert Comment

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

Author Comment

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

Expert Comment

by:jkr
Comment Utility
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
Comment Utility
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
Comment Utility
Not needed - our sendmail gateway (Linux) simply kicks all of them ;-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now