[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

GetLogicalDriveString

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
DarrinE
Asked:
DarrinE
  • 5
  • 4
1 Solution
 
jkrCommented:
     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
 
DarrinEAuthor Commented:
Thanks jkr - finishing with this for an A grade answer

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

DarrinE
0
 
jkrCommented:
Ooops, have overseen this ;-)

i = 0;
for ( ;;)
{
      if ( !apszDrives [ i]) break;
      MessageBox ( NULL, apszDrives [ i++], "Drive found", MB_OK | MB_ICONINFORMATION);
}      
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
DarrinEAuthor Commented:
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
 
jkrCommented:
The maximum size is (should always) be 26 - there aren't any more letters in the alphabet ;-)
0
 
DarrinEAuthor Commented:
OK - I get it - but how can I tell how many arrays are in apszDrives ?
0
 
jkrCommented:
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
 
DarrinEAuthor Commented:
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
 
jkrCommented:
Not needed - our sendmail gateway (Linux) simply kicks all of them ;-)
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now