This function is supposed to list the directory listing to an output file. For some reason it isn't WriteFile() -ing.

int __stdcall TxtList(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show,
BOOL nopause)
{
char dir[300], output[900];
WIN32_FIND_DATA FindFileData;
HANDLE hFind = NULL;
HANDLE hFile;
Gettok(data,dir,'>',0,300);
Gettok(data,output,'>',1,900);

hFile = CreateFile(output,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

hFind = FindFirstFile(dir, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
lstrcpy(data,"No files found.");
return 3;
}

while (FindNextFile(hFind, &FindFileData) != 0) {
WriteFile(hFile,FindFileData.cFileName,strlen(FindFileData.cFileName),0,NULL);
WriteFile(hFile,"\r\n",2,0,NULL);
// lstrcpy(data,FindFileData.cFileName);
// return 3;
}

FindClose(hFind);
CloseHandle(hFile);

lstrcpy(data,"FF_OK");
return 3;
}

assistance please.