Click here to Skip to main content
15,923,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Access variables in CMyView Pin
hcmuns12-Jun-05 17:49
susshcmuns12-Jun-05 17:49 
GeneralRe: Access variables in CMyView Pin
Tom Archer12-Jun-05 18:22
Tom Archer12-Jun-05 18:22 
GeneralRe: Access variables in CMyView Pin
hcmuns12-Jun-05 21:21
susshcmuns12-Jun-05 21:21 
GeneralRe: Access variables in CMyView Pin
hcmuns12-Jun-05 22:41
susshcmuns12-Jun-05 22:41 
QuestionDoes anyone know RLC? Pin
Member 199230312-Jun-05 17:12
Member 199230312-Jun-05 17:12 
GeneralMessage forwarding.... Pin
dobrzan12-Jun-05 11:20
dobrzan12-Jun-05 11:20 
GeneralSimple grid in a view Pin
scientist4712-Jun-05 10:22
scientist4712-Jun-05 10:22 
GeneralReturning a value from a Worker Thread Pin
Steve Messer12-Jun-05 8:41
Steve Messer12-Jun-05 8:41 
I have a function that recursively counts the number of files of a given type from the specified path.

It works as desired when used as a regualar function but I am trying to use this function in a worker thread that would return the number of files counted.

I have tried everything that I can think of but the results is always zero.

Here is the struct that I pass as a param to the threadproc

struct THREADSTRUCT
{
    CString filename;
    int count;
} ;


Here is my calling function.


int CPlayer::CountFiles( string path )
{
    _paramCount->filename = path.c_str();
    _paramCount->count = 0;
    AfxBeginThread( Count, _paramCount );
   
    return _paramCount->count; // this is one of many attempts
}


Here is my threadproc

UINT Count( LPVOID pParam ) 
{
	THREADSTRUCT*    ts = (THREADSTRUCT*)pParam;
	assert( !ts->filename.IsEmpty() );
	int count = 0;
 		
	vector< string > files;
	vector< string > dirs;

	string path = ts->filename.GetBuffer();

	string types[] = 
	{
	  ".mp3",".mp2",".mp1",".ogg",".flac",".flc",".mpc",".ape",".ofr",".mpa",".wma"
	};

	int size = dim(types);

	if( *(path.end() - 1) != '\\' && *(path.end() - 1) != '/' )
		path += '\\';
	
	string spec( path + "*.*" );

	_finddata_t fd;
	int handle = (int)_findfirst( spec.c_str(), &fd );
	if( handle == -1 )
	    return 0;
	do
	{
		if( fd.attrib & _A_SUBDIR )
		{
		    if( fd.name != string(".") && fd.name != string("..") )
			dirs.push_back( path + fd.name );
		}
		else
		{
		    if( find_if( types, types+size, is_ext( fd.name ) ) != types+size )
		    {
			files.push_back( path + fd.name );
			count++;
			ts->count++;
			ct++;
			pCPlayer->_paramCount->count++;
			//TRACE( "TS COUNT : %d", ts->count); TRACE("\n");
		    }
		}
	}while( !_findnext( handle, &fd ) );
	_findclose(handle );

	for( size_t i=0; i<dirs.size(); ++i )
	{
	    pCPlayer->_paramCount->filename = dirs[i].c_str(); 
            count += (int)Count( pCPlayer->_paramCount ); 		
	}

	return count;  
}


I have tried global variables and nothing seems to work. What am I missing?
GeneralRe: Returning a value from a Worker Thread Pin
DavidR_r12-Jun-05 9:38
DavidR_r12-Jun-05 9:38 
GeneralRe: Returning a value from a Worker Thread Pin
Steve Messer12-Jun-05 10:29
Steve Messer12-Jun-05 10:29 
GeneralRe: Returning a value from a Worker Thread Pin
Tom Archer12-Jun-05 13:44
Tom Archer12-Jun-05 13:44 
GeneralRe: Returning a value from a Worker Thread Pin
Steve Messer12-Jun-05 16:38
Steve Messer12-Jun-05 16:38 
GeneralRe: Returning a value from a Worker Thread Pin
Tom Archer12-Jun-05 18:20
Tom Archer12-Jun-05 18:20 
Generalimage processing Pin
prabhathgk12-Jun-05 7:51
prabhathgk12-Jun-05 7:51 
GeneralRe: image processing Pin
DavidR_r12-Jun-05 9:41
DavidR_r12-Jun-05 9:41 
GeneralDelta time in mSec Pin
Ravi Bhavnani12-Jun-05 6:48
professionalRavi Bhavnani12-Jun-05 6:48 
GeneralSolved! Pin
Ravi Bhavnani12-Jun-05 7:34
professionalRavi Bhavnani12-Jun-05 7:34 
GeneralAre function calls that costly? Need help optimizing Pin
Budric B.12-Jun-05 6:32
Budric B.12-Jun-05 6:32 
GeneralRe: Are function calls that costly? Need help optimizing Pin
liquid_12-Jun-05 7:35
liquid_12-Jun-05 7:35 
GeneralRe: Are function calls that costly? Need help optimizing Pin
Budric B.12-Jun-05 7:52
Budric B.12-Jun-05 7:52 
GeneralRe: Are function calls that costly? Need help optimizing Pin
squidev12-Jun-05 7:44
squidev12-Jun-05 7:44 
GeneralRe: Are function calls that costly? Need help optimizing Pin
Tom Archer12-Jun-05 13:50
Tom Archer12-Jun-05 13:50 
GeneralRe: Are function calls that costly? Need help optimizing Pin
PJ Arends12-Jun-05 17:35
professionalPJ Arends12-Jun-05 17:35 
GeneralRe: Are function calls that costly? Need help optimizing Pin
Budric B.13-Jun-05 4:09
Budric B.13-Jun-05 4:09 
GeneralCapturing Sound Pin
Identity Undisclosed12-Jun-05 6:18
Identity Undisclosed12-Jun-05 6:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.