I have a program which needs to take the logical drives returned from the GetLogicalDriveString function and store them in a string array for later use in a filepath. I tried doing this directly and it failed. Here's my code:
Code:#include "stdafx.h" #include <iostream> #include <io.h> #include <time.h> #include <string> #include <windows.h> #include <direct.h> #include <stdio.h> #include <tchar.h> #include <Lmcons.h> #include <sstream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { CHAR name [ UNLEN + 1 ]; DWORD size = UNLEN + 1; if (GetUserName( (CHAR*)name, &size )) wcout << L"Hello, " << name << L"!\n"; else cout << "Hello, unnamed person!\n"; TCHAR szBuffer[1024]; ::GetLogicalDriveStrings(1024, szBuffer); TCHAR *pch = szBuffer; while (*pch) { _tprintf(TEXT("%s\n"), pch); pch = &pch[_tcslen(pch) + 1]; } int arraylength = sizeof( pch ); cout << arraylength << endl; string drive[1025]; int i; i = 0; if (i < arraylength) { i++; drive[i] = pch[i]; cout << drive[i] << endl; } return 0; }



LinkBack URL
About LinkBacks


