Click here to Skip to main content
15,902,198 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to monitor the status of a process. Pin
Jörgen Sigvardsson26-Oct-03 0:52
Jörgen Sigvardsson26-Oct-03 0:52 
GeneralRe: How to monitor the status of a process. Pin
George226-Oct-03 1:06
George226-Oct-03 1:06 
GeneralRe: How to monitor the status of a process. Pin
Jörgen Sigvardsson26-Oct-03 1:13
Jörgen Sigvardsson26-Oct-03 1:13 
GeneralRe: How to monitor the status of a process. Pin
George226-Oct-03 1:24
George226-Oct-03 1:24 
GeneralDial-Up Server programming for win98 Pin
Reza Azizi25-Oct-03 23:31
Reza Azizi25-Oct-03 23:31 
GeneralDLL problem Pin
Ghasrfakhri25-Oct-03 21:38
Ghasrfakhri25-Oct-03 21:38 
GeneralRe: DLL problem Pin
Jörgen Sigvardsson26-Oct-03 0:26
Jörgen Sigvardsson26-Oct-03 0:26 
GeneralATL collection and event firing Pin
Paul Farry25-Oct-03 19:45
professionalPaul Farry25-Oct-03 19:45 
I've got an ATL component that is used to get a Directory listing async for VB clients.

I have 3 interfaces in my Component.
IListing
IDirectory
IFileObject

I listing exposes a method of ExecuteImmediate, and Execute(it creates a thread to do the work).

It then uses the FindFirstFile/FindFirstFile etc to actually do the work.
In this area of the component, I create a CComObject<cdirectory> and store that in the member variable for my component.
Then the hard work is done, and each CComObject<fileobject> as added to the CDirectory object.

All this works perfectly. No leaks, etc.

I then call a property (Contents) to return the IDirectory which is my enumeration of the objects. Also fine.

If I add to the bottom of the ExecuteImmediate/Execute and Event to Fire_Complete(). The system crashes. I've gone through with the debugger, and I can't find anything.


I would really appreciate it if someone could identify any problems with this code(or if I should include some more).

<br />
<br />
DWORD WINAPI SearchFilesFunction2( LPVOID lpParam )<br />
{<br />
	SearchFunction(lpParam);<br />
	ExitThread(0);<br />
    return 0;   // thread completed<br />
<br />
}<br />
<br />
void SearchFunction( LPVOID lpParam )<br />
{<br />
	USES_CONVERSION;<br />
	CListing2* pListing;<br />
	CComBSTR path;<br />
	LPTSTR lpsz;<br />
	BSTR	directoryPath;<br />
	BSTR	directoryMask;<br />
	bool Finished;<br />
<br />
	WIN32_FIND_DATA FileFindData; <br />
	HANDLE hSearch; <br />
<br />
	pListing = (CListing2*)lpParam;<br />
<br />
	pListing->m_inProgress = TRUE;<br />
<br />
	lpsz = new TCHAR[512];<br />
	pListing->get_Directory(&directoryPath);<br />
	pListing->get_Mask(&directoryMask);<br />
<br />
	path = directoryPath;<br />
	path += directoryMask;<br />
<br />
	hSearch = FindFirstFile(OLE2CT(path), &FileFindData); <br />
<br />
	Finished = FALSE;<br />
<br />
	if (hSearch == INVALID_HANDLE_VALUE) <br />
	{ <br />
		Finished= TRUE;<br />
	} <br />
<br />
	pListing->pDirectory = new CComObject<CDirectory>;<br />
	<br />
	while (!Finished) <br />
	{ <br />
<br />
		CComBSTR fullpath;<br />
		BSTR bstr_Filename;<br />
<br />
		CFileObject * pFileObject;<br />
		pFileObject = new CComObject<CFileObject>;<br />
<br />
		_tcscpy( lpsz, FileFindData.cFileName );<br />
<br />
		bstr_Filename = SysAllocString(lpsz);<br />
<br />
		fullpath = directoryPath;<br />
		fullpath +=  bstr_Filename;<br />
<br />
		pFileObject->put_Name(bstr_Filename);<br />
		pFileObject->put_Path(directoryPath);<br />
<br />
		if (FileFindData.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY))<br />
		{<br />
			pFileObject->put_Type(1);<br />
			fullpath += "\\";<br />
		}<br />
		else<br />
		{<br />
			pFileObject->put_Type(0);<br />
		}<br />
<br />
		pFileObject->put_Fullpath(fullpath);<br />
<br />
		SysFreeString(bstr_Filename);<br />
<br />
		pListing->pDirectory->Add(pFileObject);<br />
<br />
<br />
		if (!FindNextFile(hSearch, &FileFindData)) <br />
		{<br />
			if (GetLastError() == ERROR_NO_MORE_FILES) <br />
			{ <br />
				Finished= TRUE;<br />
			} <br />
			else <br />
			{ <br />
				Finished= TRUE;<br />
			} <br />
		}<br />
    }<br />
<br />
	SysFreeString(directoryPath);<br />
	SysFreeString(directoryMask);<br />
	delete [] lpsz;<br />
	<br />
	FindClose(hSearch);<br />
	pListing->m_inProgress = FALSE;<br />
        pListing->Fire_Complete();<br />
}<br />
<br />
STDMETHODIMP CListing2::Execute()<br />
{<br />
<br />
	m_inProgress = TRUE;<br />
<br />
	hThread = CreateThread( <br />
                  NULL,				<br />
                  0,<br />
                  SearchFilesFunction2,<br />
                  this,        <br />
                  0,<br />
                  &dwThreadId);<br />
 <br />
	CloseHandle(hThread);<br />
	return S_OK;<br />
}<br />
<br />
<br />
STDMETHODIMP CListing2::ExecuteImmediate()<br />
{<br />
	m_inProgress = TRUE;<br />
	SearchFunction(this);<br />
	m_inProgress = FALSE;<br />
	return S_OK;<br />
}<br />
<br />
STDMETHODIMP CListing2::get_Contents(IDirectory **pVal)<br />
{<br />
	HRESULT hr;<br />
	if (!m_inProgress)<br />
	{<br />
//When the Event is Fired, this crashes.<br />
//If the event isn't fired, it's all fine.<br />
<br />
		hr = pDirectory->QueryInterface(IID_IDispatch, (void **)pVal); <br />
		return S_OK;<br />
	}<br />
	else<br />
	{<br />
		return S_FALSE;<br />
	}<br />
}<br />
<br />
<br />

GeneralRe: ATL collection and event firing Pin
Jörgen Sigvardsson26-Oct-03 0:34
Jörgen Sigvardsson26-Oct-03 0:34 
GeneralWhats the IP Mr. Winsock? (How can I find out a connected persons IP) Pin
STS_Secure_Telnet25-Oct-03 19:38
STS_Secure_Telnet25-Oct-03 19:38 
GeneralRe: Whats the IP Mr. Winsock? (How can I find out a connected persons IP) Pin
andyvinc25-Oct-03 21:35
andyvinc25-Oct-03 21:35 
Generalcharacter presentation Pin
convert_sg25-Oct-03 19:11
convert_sg25-Oct-03 19:11 
GeneralRe: character presentation Pin
Gary R. Wheeler26-Oct-03 6:10
Gary R. Wheeler26-Oct-03 6:10 
GeneralRe: character presentation Pin
convert_sg29-Oct-03 15:18
convert_sg29-Oct-03 15:18 
Questionhow to detect when an app is invoked from another running application Pin
raishum25-Oct-03 19:09
raishum25-Oct-03 19:09 
AnswerRe: how to detect when an app is invoked from another running application Pin
igor196026-Oct-03 10:02
igor196026-Oct-03 10:02 
GeneralToggling the password style in an edit box Pin
Michael Dunn25-Oct-03 17:56
sitebuilderMichael Dunn25-Oct-03 17:56 
GeneralRe: Toggling the password style in an edit box Pin
Gary R. Wheeler26-Oct-03 6:43
Gary R. Wheeler26-Oct-03 6:43 
GeneralRe: Toggling the password style in an edit box Pin
Michael Dunn26-Oct-03 6:54
sitebuilderMichael Dunn26-Oct-03 6:54 
GeneralRe: Toggling the password style in an edit box Pin
igor196026-Oct-03 10:08
igor196026-Oct-03 10:08 
GeneralRe: Toggling the password style in an edit box Pin
Michael Dunn26-Oct-03 20:19
sitebuilderMichael Dunn26-Oct-03 20:19 
QuestionHow to kill a process by its processID? Pin
George225-Oct-03 17:18
George225-Oct-03 17:18 
AnswerRe: How to kill a process by its processID? Pin
Michael Dunn25-Oct-03 17:36
sitebuilderMichael Dunn25-Oct-03 17:36 
GeneralRe: How to kill a process by its processID? Pin
George225-Oct-03 23:11
George225-Oct-03 23:11 
AnswerRe: How to kill a process by its processID? Pin
Carlos Antollini25-Oct-03 17:45
Carlos Antollini25-Oct-03 17:45 

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.