Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionFree fails with Access violation reading location Pin
tejaswini_g24-Mar-14 13:31
tejaswini_g24-Mar-14 13:31 
AnswerRe: Free fails with Access violation reading location Pin
Richard Andrew x6424-Mar-14 13:42
professionalRichard Andrew x6424-Mar-14 13:42 
GeneralRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 15:01
tejaswini_g24-Mar-14 15:01 
AnswerRe: Free fails with Access violation reading location Pin
leon de boer24-Mar-14 15:06
leon de boer24-Mar-14 15:06 
GeneralRe: Free fails with Access violation reading location Pin
User 5924124-Mar-14 15:25
User 5924124-Mar-14 15:25 
GeneralRe: Free fails with Access violation reading location Pin
User 5924124-Mar-14 15:59
User 5924124-Mar-14 15:59 
QuestionRe: Free fails with Access violation reading location Pin
User 5924124-Mar-14 15:17
User 5924124-Mar-14 15:17 
AnswerRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 15:39
tejaswini_g24-Mar-14 15:39 
I am posting compiled code. As stated above Freelist[i] fails. Highlighted the statement causing error.

#include <<windows.h>> // remove extra angle bracket for compilation
#include <<tchar.h>>
#include <<stdio.h>>
#include <<strsafe.h>>

void FreeMemory(char** myArray, int row);
void FileCountInDir(const TCHAR* dirpath, int * filescount, int* filesize);
void FindFilesInDirectory(const TCHAR* dirpath, char** filelist);

int _tmain(int argc, TCHAR *argv[])
{
int i =0;
TCHAR szDirpath[MAX_PATH];
//TCHAR Filelist[100][MAX_PATH];
char ** Filelist;
int iFileCountInFolder=0;
int iFileSize = 0;

_tcscpy(szDirpath,_T("C:\\BMPread_W\\TransitionEffects\\Images"));

FileCountInDir(szDirpath,&iFileCountInFolder,&iFileSize);
Filelist = (char**)malloc(iFileCountInFolder * sizeof(char *));
if(Filelist == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
for(i = 0; i < iFileCountInFolder; i++)
{
Filelist[i] = (char*)malloc((iFileSize * sizeof(char))+1);
if(Filelist[i] == NULL)
{
fprintf(stderr, "out of memory\n");
return 0;
}
}
FindFilesInDirectory(szDirpath, Filelist);

for(i =0;i<ifilecountinfolder;i++)
{
="" _tprintf(text("%s\n"),filelist[i]);
="" }
="" freememory(filelist,ifilecountinfolder);
="" return="" 0;
}
void="" findfilesindirectory(const="" tchar*="" dirpath,="" char**="" filelist)
{
="" list="" all="" the="" files="" in="" directory="" with="" some="" info="" about="" them.

="" win32_find_data="" ffd;
="" tchar="" szdir[max_path];
="" szfilefullpath[max_path]="{0};
" int="" filenumber="0;
" handle="" hfind="INVALID_HANDLE_VALUE;
" dword="" dwerror="0;


" _tcscpy(szdir,="" dirpath);
="" _tcscat(szdir,_t("\\*"));

="" &ffd);

="" if="" (invalid_handle_value="=" hfind)=""
="" ;
="" }="" do
="" (ffd.dwfileattributes="" &="" file_attribute_directory)
="" do="" nothing
="" else
="" _tcscpy(szfilefullpath,dirpath);
="" _tcscat(szfilefullpath,_t("\\"));
="" _tcscat(szfilefullpath,ffd.cfilename);
="" memcpy(filelist[filenumber],="" ffd.cfilename,="" sizeof(ffd.cfilename));
="" filenumber++;
="" while="" (findnextfile(hfind,="" &ffd)="" !="0);
" findclose(hfind);
}
void="" filecountindir(const="" *="" filescount,="" int*="" filesize)
{
="" szfilefullpath="{0};

" &ffd);
="" (*filescount)++;
="" if(="" ((*filesize)="=" 0)="" &&="" (_tcslen(ffd.cfilename)=""> 0)|| ((*filesize) < _tcslen(ffd.cFileName)))
{
(*filesize) = _tcslen(ffd.cFileName);
}
}
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
}

void FreeMemory(char** myArray, int row)
{
int i;
if(myArray != NULL)
{
for (i = 0; i < row; i++){
free (myArray[i]);


}
}
AnswerRe: Free fails with Access violation reading location Pin
User 5924124-Mar-14 16:01
User 5924124-Mar-14 16:01 
GeneralRe: Free fails with Access violation reading location Pin
tejaswini_g24-Mar-14 16:11
tejaswini_g24-Mar-14 16:11 
QuestionHow do you define flags? Pin
Dusan Paulovic24-Mar-14 9:48
Dusan Paulovic24-Mar-14 9:48 
AnswerRe: How do you define flags? Pin
Richard MacCutchan24-Mar-14 11:11
mveRichard MacCutchan24-Mar-14 11:11 
AnswerRe: How do you define flags? Pin
Albert Holguin25-Mar-14 4:48
professionalAlbert Holguin25-Mar-14 4:48 
QuestionHow do I using WH_CALLWNDPROC and PT_TOUCH to get the global touch event Pin
cedricvictor24-Mar-14 3:48
cedricvictor24-Mar-14 3:48 
Questionvisual studio 6.0 Enterprise edition License Pin
KrishnaRayalu_Talisetti24-Mar-14 0:47
KrishnaRayalu_Talisetti24-Mar-14 0:47 
AnswerRe: visual studio 6.0 Enterprise edition License Pin
Jochen Arndt24-Mar-14 1:02
professionalJochen Arndt24-Mar-14 1:02 
AnswerRe: visual studio 6.0 Enterprise edition License Pin
David Crow24-Mar-14 4:51
David Crow24-Mar-14 4:51 
QuestionBuilding / compiling DirectShow "empty DLL". Pin
Vaclav_23-Mar-14 5:51
Vaclav_23-Mar-14 5:51 
SuggestionRe: Building / compiling DirectShow "empty DLL". Pin
Richard MacCutchan23-Mar-14 22:59
mveRichard MacCutchan23-Mar-14 22:59 
QuestionWin CE program, SetFong() not work Pin
econy21-Mar-14 7:21
econy21-Mar-14 7:21 
AnswerRe: Win CE program, SetFong() not work Pin
Rage25-Mar-14 2:15
professionalRage25-Mar-14 2:15 
AnswerRe: Win CE program, SetFong() not work Pin
Rage25-Mar-14 2:17
professionalRage25-Mar-14 2:17 
GeneralRe: Win CE program, SetFong() not work Pin
econy25-Mar-14 3:32
econy25-Mar-14 3:32 
QuestionWidth of dropdown list window Pin
bokideclan21-Mar-14 2:33
bokideclan21-Mar-14 2:33 
QuestionVery weird change font problem Pin
econy20-Mar-14 8:18
econy20-Mar-14 8:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.