954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Win32_FIND_DATA FindFirstFile

Hello everybody,
I have recently joined this forum. I am facing a problem of which I cannot see any solution anywhere. :sad:
Please help.
I am trying to write a C program in MSDEV(VC++6.0).
My problem is "FindFileData.cFileName" is picking only the first letter of the existing filename, and so later on any operations using the file is being impossible.Any suggestions to rectify this? It worked with WinCE, but not working with WinXP.
A piece of code is as follows:
--------------------------------------
#include "stdafx.h"
#include
#include
#include
#include
#include

#define MAX_LENGTH 100

ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
WIN32_FIND_DATA FindFileData;

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
STARTUPINFO si1;
PROCESS_INFORMATION pi1;

ZeroMemory(&pi1, sizeof(pi1));
ZeroMemory(&si1, sizeof(si1));
si1.cb = sizeof(si1);
SECURITY_ATTRIBUTES saProcess, saThread ;


HANDLE hSearch;
DWORD dwExitCode =0;
DWORD dwCheckProcess;
HANDLE processHandle;
TCHAR sFileName[MAX_PATH];
TCHAR sDirName[MAX_PATH];
TCHAR sDirectory[MAX_LENGTH];
TCHAR sCmdLine[MAX_LENGTH];
FILE *log_file;
FILE *result_file;
BOOL first_time=TRUE;
BOOL RUN_FLAG=TRUE;


saProcess.nLength = sizeof(saProcess) ;
saProcess.lpSecurityDescriptor = NULL ;
saProcess.bInheritHandle = TRUE ;

saThread.nLength = sizeof(saThread) ;
saThread.lpSecurityDescriptor = NULL ;
saThread.bInheritHandle = FALSE ;

log_file=fopen("log.txt", "w");
result_file=fopen("results.txt", "w");

lstrcpy (sDirectory, "264\\*.264");
hSearch = FindFirstFile(sDirectory, &FindFileData);

if (hSearch == INVALID_HANDLE_VALUE)
{
fprintf(log_file, "Couldn't pick file\n");
return NULL;
}
else
{
do
{

strcpy (sDirName, TEXT(" -i 264\\"));
lstrcpy(sFileName,FindFileData.cFileName );
strcat(sDirName,sFileName);

// Create the process to run the application
if(!CreateProcess("h264.exe",sDirName,&saProcess, &saThread,FALSE,DETACHED_PROCESS,NULL,NULL,&si1,&pi1))
{
fprintf(log_file, "CreateProcess failed. Error is %d", GetLastError());
exit(1);

}
}
-------------------------------------------------------------------------
As "FindFirstFile" is not picking the complete filename, but just the first letter, My createprocess() couldn't find the file referred to and fails.Is it an OS issue? How do I correct it?
Thanks
Princess_lia :)

princess_lia
Newbie Poster
1 post since Apr 2006
Reputation Points: 10
Solved Threads: 0
 
Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

your do-while loop is wrong. It doesn't even compile so I'm not supprised it has runtime errors.

do
	{
			strcpy (sDirName, TEXT(" -i 264\\")); 
			lstrcpy(sFileName,FindFileData.cFileName );
			strcat(sDirName,sFileName);
			// other stuff here

	} while( FindNextFile(hSearch,&FindFileData) != 0);


fix that and it works.

Ancient Dragon
Retired & Loving It
Team Colleague
30,050 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You