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 <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <string.h>
#include <shlobj.h>

#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 :)

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.