lundi 13 juillet 2015

Debug Assertion Failed: _CrtIsValidHeapPointer(pUserData) C++

I'm a beginner in c++, and I tried to write a program that randomly generates me an episode from one of my favourite serials, or absolute randomly, but when I debug it, this error always come up. The code is OK, if it's not in Win32 Form app, it works. Could you please help me?

My Code is hear, if it helps:

List item

Void pro::Form1::keres(string sori) {


int k=0;
vector<string> a;
srand (time(NULL));
string desti = "d:\\Filmek\\Sorozatok\\" + sori + "\\*";
WIN32_FIND_DATA search_data;
int s;

memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
HANDLE handle = FindFirstFile(desti.c_str(), &search_data);

while(handle != INVALID_HANDLE_VALUE)
{
    a.push_back(search_data.cFileName);
    k++;
    if(FindNextFile(handle, &search_data) == FALSE)
        break;
}

s = rand() % (k-2);
cout<<a[s+2]<<endl;
desti = "d:\\Filmek\\Sorozatok\\" + sori + "\\" + a[s+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
k = 0;

while(handle != INVALID_HANDLE_VALUE)
{
    a.push_back(search_data.cFileName);
    k++;
    if(FindNextFile(handle, &search_data) == FALSE)
        break;
}
s = rand() % (k-2);
string run = "cd " + desti + " & start " + a[s+2];
system(run.c_str());
a.clear();
}

Void pro::Form1::kereses(string film) {

int q=0;
int w=0;
int e=0;

int a;
int s;
int d;

vector<string> y;
vector<string> x;
vector<string> v;
srand (time(NULL));

string desti = "d:\\Filmek\\" + film + "\\*";
WIN32_FIND_DATA search_data;

memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
HANDLE handle = FindFirstFile(desti.c_str(), &search_data);

while(handle != INVALID_HANDLE_VALUE)
{
    y.push_back(search_data.cFileName);
    q++;
    if(FindNextFile(handle, &search_data) == FALSE)
        break;
}

a = rand() % (q-2);
desti = "d:\\Filmek\\" + film +"\\" + y[a+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
y.clear();
q = 0;

while(handle != INVALID_HANDLE_VALUE)
{
    x.push_back(search_data.cFileName);
    w++;
    if(FindNextFile(handle, &search_data) == FALSE)
        break;
}

s = rand() % (w-2);
desti = "d:\\Filmek\\" + film +"\\" + y[a+2] + "\\" + x[s+2] + "\\*";
handle = FindFirstFile(desti.c_str(), &search_data);
x.clear();
w = 0;

while(handle != INVALID_HANDLE_VALUE)
{
    v.push_back(search_data.cFileName);
    e++;
    if(FindNextFile(handle, &search_data) == FALSE)
        break;
}
d = rand() % (e-2);
string run = "cd " + desti + " & start " + v[d+2];
system(run.c_str());
v.clear();
e=0;

}




Aucun commentaire:

Enregistrer un commentaire