I am getting Access violation error from the debugger, but I really have no idea why. I suspect that it would be something really stupid.
I have an array of directory entries:
typedef struct dirEntry{
TCHAR fileName[MAX_PATH];
DWORD fileSizeLow;
DWORD fileSizeHigh;
} dirEntry;
DWORD bufferSize = MEM_SIZE; //MEM_SIZE = 100
DWORD bufferPosition = 0;
dirEntry* dirBuffer;
dirBuffer = (dirEntry*) malloc(bufferSize*sizeof(dirEntry));
Then I pass it to a function ListDirectory(_T("D:\\books\\*"), dirBuffer, &bufferSize, &bufferPosition)
Inside the function I retrieve information about the files inside, but when I call this:
dirBuffer[*bufferPosition].fileSizeLow = dataFound.nFileSizeLow;
_tcscpy(dirBuffer[*bufferPosition].fileName, dataFound.cFileName);
*bufferPosition++;
The first line produces an exception. Can somebody please tell me what I’m doing wrong?
EDIT: Code of ListDirectory as demanded: http://pastebin.com/ScbcqX7p
*bufferPosition++does not do what you think it does. It dereferencesbufferPosition, then increments the pointer, not the value pointed to. You probably wanted(*bufferPosition)++, which increments the pointed-to value.Mind you, it’s not clear why you are passing
bufferPositionandbufferSizeby address, since they are useless to the caller, sinceListDirectoryfrees the data the variables refer to.