?
Solved

GetLogicalDriveString

Posted on 2000-05-06
9
Medium Priority
?
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

764 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