Solved

GetLogicalDriveString

Posted on 2000-05-06
9
427 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio Exe Issue, 12 38
VS2015 compilation and missing DLLs 9 181
Is COM supported from Apache 1 74
Where does legacy ASP.NET initialize language? 2 63
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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