hello guys i tried to make a hwid login for a app. The problem is when i compile all the code i have this error.
Error C2676 binary '==': 'std::basic_string,std::allocator>' does not define this operator or a conversion to a type acceptable to the predefined operator
#include <Windows.h>
#include <iostream>
#include <tchar.h>
#include <intrin.h>
#include <TlHelp32.h>
#include <algorithm>
#include <vector>
using namespace std;
vector<string> serial;
vector<string> windows;
void loadserial()
{
serial.push_back("1731602307");
}
void loadWindows()
{
windows.push_back("29548");
}
int main()
{
TCHAR volumeName[MAX_PATH + 1] = { 0 };
TCHAR fileSystemName[MAX_PATH + 1] = { 0 };
DWORD serialNumber = 0;
DWORD maxComponentLen = 0;
DWORD fileSystemFlags = 0;
if (GetVolumeInformation(
_T("C:\\"),
volumeName,
ARRAYSIZE(volumeName),
&serialNumber,
&maxComponentLen,
&fileSystemFlags,
fileSystemName,
ARRAYSIZE(fileSystemName)))
{
}
int cpuinfo[4] = { 0, 0, 0, 0 };
__cpuid(cpuinfo, 0);
char16_t hash = 0;
char16_t* ptr = (char16_t*)(&cpuinfo[0]);
for (char32_t i = 0; i < 8; i++)
hash += ptr[i];
while (true)
{
if (find(serial.begin(), serial.end(), serialNumber) != serial.end())
{
std::cout << "nice you are in our auth system!!";
}
else
{
std::cout << "you arent in the whitelist ;(";
}
}
return(0);
}
OK, now it's clear
find(serial.begin(), serial.end(), serialNumber)
serial is a vector<string> but serialNumber is a DWORD. You can't use find to look for a DWORD in a vector of strings. I guess you need to convert the DWORD to a string first, or maybe you could change serial to a vector<DWORD>.
And as drescherjm says get into the habit of looking at the output tab for your error messages, it's much more useful than the error list (which for some reason microsoft insist on showing you first).
Related
I'm trying to use CNG to encrypt some data with a public key that is given as a parameter. When calling NCryptImportKey function, I get a NTE_BAD_DATA error which isn't listed in the msdn page.
My code:
#include <iostream>
#include <Windows.h>
#include <Bcrypt.h>
#include <Ntstatus.h>
#include <string>
#include <vector>
#include "base64.h"
using std::string;
using std::vector;
struct MyRSAPublicBlob {
BCRYPT_RSAKEY_BLOB blob;
BYTE exponent[3];
BYTE modulus[128];
MyRSAPublicBlob(const vector<BYTE>& mod, const vector<BYTE>& exp)
{
blob.BitLength = (128 + 3) * 8;
blob.Magic = BCRYPT_RSAPUBLIC_MAGIC;
blob.cbModulus = 128;
blob.cbPublicExp = 3;
for (size_t i = 0; i < mod.size(); ++i) //copy BigEndian
modulus[i] = mod[mod.size() - 1 - i];
for (size_t i = 0; i < exp.size(); ++i) //copy BigEndian
exponent[i] = exp[exp.size() - 1 - i];
}
MyRSAPublicBlob() { ; }
};
MyRSAPublicBlob b;
bool RSA_encrypt() {
SECURITY_STATUS stat;
NCRYPT_PROV_HANDLE hProv;
NCRYPT_KEY_HANDLE hKey;
stat = NCryptOpenStorageProvider(&hProv, MS_KEY_STORAGE_PROVIDER, 0);
if (ERROR_SUCCESS != stat) {
std::cout << "failed in NCryptOpenStorageProvider: " << GetLastError() << std::endl;
return false;
}
stat = NCryptImportKey(hProv,
NULL,
BCRYPT_RSAPUBLIC_BLOB,
NULL,
&hKey,
(PBYTE)&b.blob,
sizeof(b),
0);
if (ERROR_SUCCESS != stat) {
std::cout << "failed in NCryptImportKey: " << GetLastError() << std::endl;
return false;
}
Example of how I construct MyRSAPublicBlob:
string PubKeyModulus = "yVUndgQFuB5Z5FgC0/WgWCg6Y8VuB582avGjQDdeoJDa1+RBKCyXo700sAMSGjM/bVakOlFqvCsVFNBysx1CH731CDb2DR1a0bsmYmDQ9d0ZHX+AOohVDIx9mc7bkDQZoEFpe9NqFsu95Y9yktpl1JKPmKyLOFgufGJYYvQyoOM=";
string PubKeyExp = "AQAB";
vector<BYTE> PubKeyModulus_bin = base64_decode(PubKeyModulus);
vector<BYTE> PubKeyExp_bin = base64_decode(PubKeyExp);
struct MyRSAPublicBlob c(PubKeyModulus_bin, PubKeyExp_bin);
b = c;
Anything I'm doing bluntly wrong?
An RSA public key BLOB (BCRYPT_RSAPUBLIC_BLOB) has the following format in contiguous memory. Try using #pragma pack to avoid any padding issues. For example,
#pragma pack(push, 1)
struct MyRSAPublicBlob {
BCRYPT_RSAKEY_BLOB blob;
BYTE exponent[3];
BYTE modulus[32];
...};
#pragma pack(pop)
The BitLength value is the "size of the key", which for RSA means "the size of the Modulus value". So it's sort of redundant with cbModulus, but c'est la vie.
If you remove the + 3 in your calculation of BitLength it'll probably start working. Compare to .NET building the blob for RSACng.ImportParameters: http://source.dot.net/#System.Security.Cryptography.Cng/Common/System/Security/Cryptography/RSACng.ImportExport.cs,79
I'm attempting to fill a SAFEARRAY of 10 indexes of BSTR type with the value "test" and print out to console the value of each index of the SAFEARRAY after it has been assigned to verify correctness. I ran the debugger and got these values below for the first 5 indexes (my SAFEARRAY is called sa). Somehow I am iterating the SAFEARRAY incorrectly or using the wrong types, each index should be "test". Any advice on what im doing wrong?
sa[0] = "test"
sa[1] = "est"
sa[2] = "st"
sa[3] = "t"
sa[4] = ""
....
#include <iostream>
#include <string>
#include <Windows.h>
#include <atlbase.h>
#include <comutil.h>
#include <string.h>
#include <stdio.h>
using namespace std;
void fillVariant(VARIANT& varIn, BSTR &srcArray);
int main()
{
BSTR *theArray = new BSTR[10];
for(int i = 0 ; i < 10; i++)
{
theArray[i] = SysAllocString(L"test");
}
VARIANT variantArray;
fillVariant(variantArray, *theArray);
return 0;
}
void fillVariant(VARIANT& varIn, BSTR &srcArray)
{
VARIANT *variantArray = &varIn;
VariantInit(variantArray);
variantArray->vt = VT_ARRAY|VT_BSTR;
SAFEARRAY* sa;
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound = 0;
aDim[0].cElements = 10;
sa = SafeArrayCreate(VT_BSTR, 1, aDim);
BSTR* dwArray = NULL;
SafeArrayAccessData(sa, (void**)&dwArray);
for(int i = 0; i < 10; i++)
{
dwArray[i] = &srcArray[i];
BSTR tmp = (BSTR) dwArray[i];
std::wstring ws(tmp);
//std::wstring ws(*dwArray[i], SysStringLen(dwArray[i]));
std::wcout << ws << endl;
}
SafeArrayUnaccessData(sa);
variantArray->parray = sa;
}
You are not filling in the VARIANT correctly. Try this instead:
#include <iostream>
#include <string>
#include <Windows.h>
#include <atlbase.h>
#include <comutil.h>
#include <string.h>
#include <stdio.h>
using namespace std;
void fillVariant(VARIANT& varIn, BSTR *srcArray, int srcArrayLen);
int main()
{
BSTR *theArray = new BSTR[10];
for(int i = 0 ; i < 10; i++)
{
theArray[i] = SysAllocString(L"test");
}
VARIANT variantArray;
fillVariant(variantArray, theArray, 10);
// don't forget to free memory when done!
// note: the VARIANT owns the BSTRs, so DON'T free them!
VariantClear(&variantArray);
delete[] theArray;
return 0;
}
void fillVariant(VARIANT& varIn, BSTR *srcArray, int srcArrayLen)
{
VARIANT *variantArray = &varIn;
VariantInit(variantArray);
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound = 0;
aDim[0].cElements = srcArrayLen;
SAFEARRAY* sa = SafeArrayCreate(VT_BSTR, 1, aDim);
if (sa)
{
BSTR* dwArray = NULL;
SafeArrayAccessData(sa, (void**)&dwArray);
for(int i = 0; i < srcArrayLen; i++)
{
// note: passing ownership, NOT making a copy
dwArray[i] = srcArray[i];
//std::wstring ws(dwArray[i], SysStringLen(dwArray[i]));
std::wcout << dwArray[i] << endl;
}
SafeArrayUnaccessData(sa);
variantArray->vt = VT_ARRAY|VT_BSTR;
variantArray->parray = sa;
}
}
Alternatively:
#include <iostream>
#include <string>
#include <Windows.h>
#include <atlbase.h>
#include <comutil.h>
#include <string.h>
#include <stdio.h>
using namespace std;
void fillVariant(VARIANT& varIn, BSTR *srcArray, int srcArrayLen);
int main()
{
BSTR *theArray = new BSTR[10];
for(int i = 0 ; i < 10; i++)
{
theArray[i] = SysAllocString(L"test");
}
VARIANT variantArray;
fillVariant(variantArray, theArray, 10);
// don't forget to free memory when done!
VariantClear(&variantArray);
// note: the VARIANT DOES NOT own the BSTRs, so DO free them!
for(int i = 0 ; i < 10; i++)
{
SysFreeString(theArray[i]);
}
delete[] theArray;
return 0;
}
void fillVariant(VARIANT& varIn, BSTR *srcArray, int srcArrayLen)
{
VARIANT *variantArray = &varIn;
VariantInit(variantArray);
SAFEARRAYBOUND aDim[1];
aDim[0].lLbound = 0;
aDim[0].cElements = srcArrayLen;
SAFEARRAY* sa = SafeArrayCreate(VT_BSTR, 1, aDim);
if (sa)
{
for(LONG i = 0; i < srcArrayLen; i++)
{
// note: makes a copy, DOES NOT pass ownership!
SafeArrayPutElement(sa, &i, srcArray[i]);
//std::wstring ws(srcArray[i], SysStringLen(srcArray[i]));
std::wcout << srcArray[i] << endl;
}
variantArray->vt = VT_ARRAY|VT_BSTR;
variantArray->parray = sa;
}
}
&srcArray[i] doesn't do what you think it does. srcArray is a single BSTR, which is a typedef for WCHAR*. It is not an array of BSTRs. srcArray[i] refers to the ith character in theArray[0], and &srcArray[i] is the address of that character. That's how you got "test", "est" and so on.
Have fillVariant take BSTR* as its second parameter, and pass theArray, not *theArray.
On an unrelated note, your program leaks a bunch of BSTRs and a SAFEARRAY.
I have a probelm :( i wanna make a program wich gives a random number :) i don't want use rand() function :) i wanna make one for me then turn it to a function ;) for educational purpose :)
but i have a problem :( see my code :)
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <windows.h>
#define MIN 0
#define MAX 99999
using namespace std;
typedef struct _RANDOM_INFO{
DWORD random;
DWORD min;
DWORD max;
} RANDOM_INFO, * LPRANDOM_INFO;
void Error(LPSTR lpErrorMessage){
cout << lpErrorMessage << endl;
exit(EXIT_FAILURE);
}
void GetRandom(LPVOID lpParam){
DWORD dwListSize = 10000, min = 0, max = 99999;
LPDWORD lpRandom = (LPDWORD)lpParam;
LPSTR lpFileSelf, lpKernel, lpNtdll;
HMODULE hFileSelf = NULL, hKernel = NULL, hNtdll = NULL;
hFileSelf = (HMODULE) GetModuleHandle(NULL);
hKernel = (HMODULE) GetModuleHandle("kernel.dll");
hNtdll = (HMODULE) GetModuleHandle("ntdll.dll");
lpFileSelf = (LPSTR) hFileSelf;
lpKernel = (LPSTR) hKernel;
lpNtdll = (LPSTR) hNtdll;
while(1){
DWORD i;
for(i = 0; i <= dwListSize; i++){
*lpRandom = (DWORD)lpFileSelf[i];
}
i = 0;
}
return;
}
int main(int argc, char **argv)
{
DWORD random = 0;
DWORD getRandomThreadId = 0;
HANDLE hGetRandomThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetRandom, &random, 0, &getRandomThreadId);
if(hGetRandomThread == INVALID_HANDLE_VALUE)
Error("Cannot make a random list.");
getch();
cout << random << endl;
Sleep(1500);
return 0;
}
The variable should get a value when and print it but i always i get 0 and a windows error can someone tell me why??? and another problem when i try to use the variable hKernel in the GetRandom function i get an error too :( but it works fine whith hFileSelf and hNtdll !!!! is kernel protected from reading???
Note : this is not a random number generation :) its just a way to get a number from the memory when the user click on the enter on his keyboard :), and its not always the same time for all users so its not always the same pointer in memory :) i hope u understand what i want do :) sorry for my bad englush :) just help me to fix the problem :)
Thank u :)
Your GetRandom() function does not have the correct signature for a CreateThread() callback procedure. Try this instead:
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <windows.h>
#define MIN 0
#define MAX 99999
using namespace std;
typedef struct _RANDOM_INFO
{
DWORD random;
DWORD min;
DWORD max;
} RANDOM_INFO, * LPRANDOM_INFO;
void Error(LPSTR lpErrorMessage)
{
cout << lpErrorMessage << endl;
exit(EXIT_FAILURE);
}
HMODULE hFileSelf = (HMODULE) GetModuleHandle(NULL);
DWORD WINAPI GetRandomThreadProc(LPVOID lpParam)
{
LPDWORD lpRandom = (LPDWORD) lpParam;
DWORD dwListSize = 10000, min = 0, max = 99999;
LPBYTE lpFileSelf = (LPBYTE) hFileSelf;
while (1)
{
for (DWORD i = 0; i <= dwListSize; ++i)
{
*lpRandom = (DWORD) lpFileSelf[i];
}
Sleep(0);
}
return 0;
}
int main(int argc, char **argv)
{
DWORD dwRandom = 0;
DWORD dwRandomThreadId = 0;
HANDLE hGetRandomThread = CreateThread(NULL, 0, &GetRandomThreadProc, &dwRandom, 0, &dwRandomThreadId);
if (hGetRandomThread == INVALID_HANDLE_VALUE)
Error("Cannot make a random list.");
do
{
getch();
cout << dwRandom << endl;
}
while (WaitForSingleObject(hGetRandomThread, 0) == WAIT_TIMEOUT);
CloseHandle(hGetRandomThread);
return 0;
}
i wanna make a program wich gives a random number
What you are doing has nothing to do with random number generation.
This is one way to do it:
Linear Congruential Generator
In the example of my computer the desired output should be: "C: E: F: H: N:" . I know it's possible, but what is the simpliest way to do that? Pottering in QueryDosDevice output
#ifndef UNICODE
#define UNICODE
#endif
#include <Windows.h>
#include <fstream>
#include <iostream>
const int REPORT_LENGTH = 5000;
int main(void)
{
TCHAR targetPath[REPORT_LENGTH];
std::ofstream oFile;
oFile.open("dos device query.txt");
QueryDosDevice(NULL,targetPath,REPORT_LENGTH);
for(int i=0; i<REPORT_LENGTH;i++)
if (targetPath[i]=='\0')(targetPath[i]='\n');
for(int i=0; i<REPORT_LENGTH; i++)
oFile<<static_cast<char>(targetPath[i]);
oFile.close();
return 0;
}
would be a huge waste of time and resources. Also function GetLogicalDriveStrings has betrayed me a lot.
#include <Windows.h>
int main()
{
TCHAR buffer[50];
GetLogicalDriveStrings(50,buffer);
MessageBox(0,buffer,"Drives in the system",MB_OK);
return 0;
}
It shows only the "C:\" volumine.
Example with GetLogicalDrives, albeit not with concatenating to a string (which is left as an exercise to the OP and the readers ;)):
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
int __cdecl _tmain(int argc, _TCHAR *argv[])
{
// Get the bit mask of drive letters
DWORD drives = ::GetLogicalDrives();
// Go through all possible letters from a to z
for(int i = 0; i < 26; i++)
{
// Check if the respective bit is set
if(drives & (1 << i))
{
// ... and if so, print it
_tprintf(TEXT("Drive %c: exists\n"), _T('A') + i);
}
}
return 0;
}
GetLogicalDriveStrings() is the way to go, you just have to use to correctly. You are assuming it returns a single string containing all of the drive strings, but that is not true. It returns an array of strings, one for each drive, so you have to loop through the array instead:
#include <windows.h>
int main()
{
TCHAR buffer[(4*26)+1] = {0};
GetLogicalDriveStrings(sizeof(buffer) / sizeof(TCHAR), buffer);
for (LPTSTR lpDrive = buffer; *lpDrive != 0; lpDrive += 4)
MessageBox(NULL, lpDrive, "Drive in the system", MB_OK);
return 0;
}
I am having a problem with my code. Whenever i run the program, the last file search would return a zero value where in it shouldn't.
here is the code:
#include <vector>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
using namespace std;
string GetPath(string path){
char directory[1024];
vector <string> filelist;
strcpy_s(directory,path.c_str());
BOOL checker;
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((LPCSTR)directory, &findFileData);
cout <<"Files in:" <<"\n"<<directory<<"\n"<<endl;
checker = FindNextFile(hFind, &findFileData);
while(checker)
{
checker = FindNextFile(hFind, &findFileData);
filelist.push_back(findFileData.cFileName);//save file list in vector
cout << findFileData.cFileName << endl;
}
DWORD error = GetLastError();
if( error != ERROR_NO_MORE_FILES)
{
}
/*for (unsigned i=1;i<filelist.size();i++){
cout << filelist[i]<<endl;//print out the vector
}*/
return 0;
}
int main()
{
string path;
path="C:\\Program Files\\*.*";
vector <string> handler;
path = GetPath(path);
}
Try this as a sanity check:
#include <tchar.h>
#include <stdexcept>
#include <vector>
#include <string>
#include <iostream>
#include <windows.h>
#ifdef UNICODE
typedef std::wstring tstring;
static std::wostream& tcout = std::wcout;
#else
typedef std::string tstring;
static std::ostream& tcout = std::cout;
#endif
std::vector<tstring> GetPath(tstring const& path)
{
WIN32_FIND_DATA findFileData;
HANDLE const hFind = FindFirstFile(path.c_str(), &findFileData);
if (hFind == INVALID_HANDLE_VALUE)
throw std::runtime_error(""); // realistically, throw something useful
std::vector<tstring> filelist;
do filelist.push_back(findFileData.cFileName);
while (FindNextFile(hFind, &findFileData));
FindClose(hFind);
if (GetLastError() != ERROR_NO_MORE_FILES)
throw std::runtime_error(""); // realistically, throw something useful
return filelist;
}
int _tmain()
{
std::vector<tstring> files = GetPath(_T("C:\\Program Files\\*.*"));
for (std::vector<tstring>::const_iterator iter = files.begin(), iter_end = files.end(); iter != iter_end; ++iter)
tcout << *iter << _T('\n');
}
If it works, clean up the error handling logic and use it ;-]. If it doesn't, then #young was correct and you you have localization issues; change your project settings to use Unicode as the character set and it should work.
First, you need to check hFind returned from FindFirstFile() as it may return INVALID_HANDLE_VALUE.
Second, your while loop should look like this
while(FindNextFile(hFind, &findFileData)!= 0)
{
filelist.push_back(findFileData.cFileName);//save file list in vector
}
DWORD error = GetLastError();
if( error != ERROR_NO_MORE_FILES)
{
// You are not expecting this error so you might want to do something here.
}
It seems to me that you shouldn't be calling FindNextFile inside the loop: I imagine that if you look at you output carefully you will notice that every SECOND file is missing from your list.
This is because the call to FindNextFile in the while condition loads the next file detail into FindFileData. Then the next line of code (inside the while loop) does this process again overwriting the first match with the second. Thus you only get every second entry.
For even numbers of files you also get the difficulty you describe at the end.
Well one thing I notice is that your GetPath function returns a string. At the end you do: return 0; This will call the string constructor that takes a char* as parameter and will attempt to construct the string with a null pointer. I assume this will lead to a crash in most STl implementations :-).
Coming to your problem, you could try this:
#include <Strsafe.h>
//from MSDN
void
DisplayError(LPTSTR lpszFunction)
{
// Retrieve the system error message for the last-error code
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0,
NULL );
// Display the error message and exit the process
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
}
void
GetPath(string path)
{
vector <string> filelist;
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile(path.c_str(), &findFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
DisplayError("FindFirstFile");
return;
}
cout <<"Enumerating files in: " <<"\n"<< path << "\n" << endl;
while( FindNextFile(hFind, &findFileData) != 0 )
{
filelist.push_back( findFileData.cFileName );//save file list in vector
}
if ( ERROR_NO_MORE_FILES != GetLastError() )
{
DisplayError("FindFirstFile");
}
FindClose(hFind);
unsigned int listSize = filelist.size();
cout << "List Count: " << listSize << "\n";
for (unsigned i=0; i < listSize; ++i)
{
cout << filelist[i] << "\n";//print out the vector
}
cout << "\nListing complete\n" << endl;
}
int main()
{
string path;
path="C:\\Program Files\\*.*";
GetPath(path);
}
And tell us what error code do you receive after the while loop completes.
This is my answer
#include <vector>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <time.h>
#include <exception>
#include <WinBase.h>
#include <tchar.h>
#include <strsafe.h>
#include <algorithm>
using namespace std;
int ifException(string directory) throw()
{
DWORD returnvalue;
returnvalue = GetFileAttributes(directory.c_str());
if(returnvalue == ((DWORD)-1))
{
return 0;
}
else
{
return 1;
}
}
string FileTime(string filename, string path){
char timeStr[ 100 ] = "";
char fpath[9999];
string buffer;
replace (path.begin(),path.end(),'*','\0');
replace (path.begin(),path.end(),'.','\0');
strcpy_s(fpath,path.c_str());
path = filename;
struct stat buf;
string filepath;
filepath = fpath;
filepath += filename;
//cout << filepath << endl;
strcpy_s(fpath,filepath.c_str());
if (!stat(fpath, &buf))
{
strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime(&buf.st_mtime));
}
buffer = filename;
buffer += "\t\t";
buffer +=timeStr;
return buffer;
}
vector <string> GetPath(string path)
{
char directory[9999];
vector <string> filelist;
string buffer;
strcpy_s(directory,path.c_str());
BOOL checker;
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile((LPCSTR)directory, &findFileData);
try
{
ifException(directory);
}catch(int i)
{
if (i==0)
{
_getch();
exit(1);
}
}
buffer = findFileData.cFileName;
filelist.push_back(buffer);
checker = FindNextFile(hFind, &findFileData);
while(checker)
{
checker = FindNextFile(hFind, &findFileData);
buffer = findFileData.cFileName;
buffer = FileTime(buffer,path);
filelist.push_back(buffer);//save file list in vector
if(checker == 0)
{
filelist.resize(filelist.size());
return filelist;
}
}
return filelist;
}
int main()
{
string path;
path="C:\\Documents and Settings\\OJT\\My Documents\\*.*";// the directory
vector <string> handler;
handler = GetPath(path);
for (unsigned i=1;i<handler.size()-1;i++)
{
cout << handler[i]<<endl;//print out the vector
}
_getch();
}