Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating file conversion...

Status
Not open for further replies.

hererxnl

Technical User
Jul 8, 2003
239
US

Sadly VC++ is not my game. I need some help, I'm totally lost.

The piece of code below allows the user to select a file through an "Open" dialog at which point the function converts the file to another file type.

The goal is to eliminate the file selection process and replace it with automatic processing based on a predefined dir. I've been stumbling my way through this and I'm now stuck.

Original Code:
Code:
case ID_OPENFILE_BTTN: {
	char	szPath[MAX_PATH] ;
	char	* pPathLast ;
	char	szWAVFileName[MAX_PATH] ;
	char	* lpExtention ;

	if ( hDS1DataFile ) {
		CloseHandle( hDS1DataFile ) ;
		hDS1DataFile = NULL ;
	}
	lpDSSFileName = GetDSSFile(hWnd) ;
	if (lpDSSFileName != NULL) {
		strcpy(szPath, lpDSSFileName) ;
		pPathLast = strrchr( szPath, '\\') ;
		pPathLast[1] = 0 ;
		uiStatus= DSSActiveFolder(szPath, FALSE) ;
		uiStatus = DSSActiveFile(lpDSSFileName, &dwMilliTotal, &DSSFileProperty) ;
	}
	strcpy(szWAVFileName, lpDSSFileName) ;
	lpExtention = strrchr( szWAVFileName, '.') ;
	strcpy(lpExtention+1, "wav") ;
	// decoder flag setting
	dwDecFlag = DSS_CONV_WAVFILE | DSS_INIT_DEC | DSS_CHANGE_PLAYPOS | DSS_USE_POSTFILT ; 
	if ( DSSFileProperty.bQuarity == MIX_RECORDED )
		dwDecFlag |= DSS_MIXED_FILE ;
	// Create WAV file header
	if ( DSS_SetupWavConversion(szWAVFileName, FALSE) != DSS_SUCCESS) {
		MessageBox(hWnd, "WAV header creating error!", "Error", MB_OK | MB_ICONEXCLAMATION);	
		return TRUE ;
	}
	uiStatus = DSSStartPlayback( 0, 0);
	if (uiStatus == DSS_SUCCESS) {
		bConvertWAVFile = TRUE ;
		dwCurPosTime = 0 ;
		dwStatus = DSS_WAVE ;
		SendMessage(GetDlgItem(hWnd, ID_PLAYPOS_SLDR), TBM_SETPOS, TRUE, dwCurPosTime) ;
	}
	break ;
}

I found some sample code that loads all files of one type, in a predefined dir, into an array, which seems like the answer. The dir and file type is "A:\\*.txt" in the example when I would need "C:\\upload\\*.dss" .

File Loop Code:
Code:
...
const char p[] = "A:\\*.txt";
...
WIN32_FIND_DATA info;
HANDLE h;

if ((h = FindFirstFile(p,&info)) != INVALID_HANDLE_VALUE)
{
  do
  {
    // Now file name C-string is in info.cFileName array
    ...
  } while(FindNextFile(h,&info));
  FindClose(h);
}
else ... // No such files.

I'm sure that this or some variation is the answer. I always know the dir of these files and after initiation of the program there is no need for human interaction in the process. Can't make it work.

Being unfamiliar with C++ is making this process brutal. Any help combining these code samples would be GREATLY appreciated.

 
you might try something like

Code:
void SearchDirAndConvert(char *pszDirPath)
{
	WIN32_FIND_DATA info;
	HANDLE h;

	if ((h = FindFirstFile(pszDirPath,&info)) != INVALID_HANDLE_VALUE)
	{
		do
		{
			convert(info.cFileName)
		} while(FindNextFile(h,&info));
		FindClose(h);
	}
	else //...  No such files.
	{
	}
}

void convert(char *pszPath)
{
	char	szWAVFileName[MAX_PATH] ;
	char	* lpExtention ;
	strcpy(szWAVFileName,pszPath)
	lpExtention = strrchr( szWAVFileName, '.') ;
	strcpy(lpExtention+1, "wav") ;

	// decoder flag setting
	dwDecFlag = DSS_CONV_WAVFILE | DSS_INIT_DEC | DSS_CHANGE_PLAYPOS | DSS_USE_POSTFILT ; 
	if ( DSSFileProperty.bQuarity == MIX_RECORDED )
		dwDecFlag |= DSS_MIXED_FILE ;

	// Create WAV file header
	if ( DSS_SetupWavConversion(szWAVFileName, FALSE) != DSS_SUCCESS)
	{
		//some error handling
	}
}
I havent actually tried this as I dont have all the other code that I would need


"If it could have gone wrong earlier and it didn't, it ultimately would have been beneficial for it to have." : Murphy's Ultimate Corollary
 

Thanks snuv, that's enough to get me restarted, maybe. :) I'll give it a go.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top