|
I have a program that search text files in a path that user define.When I click search button it start searching,but the program freeze.So I decide to put this function in a thread.
First:Is that good idea to put it in a thread and does it solve the problem of freezing?I read in MSDN that in worker thread when controlling function exists the thread terminate.My controlling function is recursive function brcause I want to search through directories so is that caused error?
Second:My controling function begins like this:
<br />
UINT FindFile(LPVOID chPath)<br />
{<br />
<br />
CString strWildcard = (CString&)(chPath);<br />
<br />
if (strWildcard == "")<br />
return 1;<br />
<br />
CFileFind finder;<br />
<br />
strWildcard += _T("\\*.*");<br />
It always afetr CFileFind finder line,thrown an unhandled error.Any idea?
Third:How can I access my controls in my dialog inside my controlling funcion?Shoud it be ALWAYS a global function?
Thanks a lot
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Probably you're having problems with chPath. I guess you should change (CString & ) to (LPCTSTR), but you didn't post your call to AfxBeginThread.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
CString str;
m_editpath.GetWindowText(str);
AfxBeginThread(FindFile,(LPVOID &)str);
Well,I change CString & to LPCSTR.I debug it and "strWildcard" is like this:
{0x003869e8 "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ"} ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char>
But there is no difference.the problem happend at CFindFile line.Not at "strWildcard" line.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Your problem is quite interesting. First of all, you're passing a reference to local CString, which is destroyed as soon as you leave the scope. So, depending on timing issues, your FindFile function may get correct string or not.
Easiest (but not elegant) way to solve this problem is to use global variable. You may also allocate a CString on the heap and pass a CString pointer to AfxBeginThread. In this case, FindFile would have to delete the string after it's no longer used.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Tomasz Sowinski wrote:
You may also allocate a CString on the heap and pass a CString pointer to AfxBeginThread.
Whats that?
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
I'm writing this right here in webpage, so take it with a grain of salt:
CString *pStr = new CString;
m_edit.GetWindowText(*pStr);
AfxBeginThread(ThreadFunc, pStr);
...
UINT ThreadFunc(LPVOID p)
{
CString *pStr = (CString *)p;
FindFile(*pStr);
delete pStr;
}
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Ohhhhh,thats perfect.It works.
Now I have another questions.How can I figure out the function finish to kill thread?Does thread kill authomaticly after function finish?
I want to update my controls in dialog box during the execution of thread,So I need to access them in my GLOBAL function. Whats the trick for that?Something like a search of windows.It update list control each time it found the new file.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Mazdak wrote:
Does thread kill authomaticly after function finish?
Yes, thread terminates automatically when controlling function finishes.
Mazdak wrote:
I want to update my controls in dialog box during the execution of thread
What kind of updating it is? Do you just want to add file names to some list control?
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Tomasz Sowinski wrote:
Do you just want to add file names to some list control?
Yes.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Just pass the dialog pointer to thread function instead of string. You'll be able get window text and add items to list as well.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Thank you very much man.You teach me a lot today.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Hi all
can any tell me the good books
or site names for understanding and implementing
the winsock programmes using MFC or related?
thanks in advance
|
|
|
|
|
Hello, the codegurus around the world.;)
One time, I also try to find the book saying "WinSock for MFC".
However, I can't find them.
Basically, we write the code of WinSock by C, and MFC is written by C++.
So, it is better to use CAsyncSocket in MFC.
Or, we can create the new Socket class by WinSock.
Some software company maybe uses WinSock and MFC, and we may create more
powerful code than CAsyncSocket. But, we need more skill to do that.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
Hello all,
We've a couple of applications using to perform regression tests. The 'front-end' application which launches and controls all.
Current situation (part of)
- Front-end launches the 'big-app' and uses a fixed delay before continue operation to give 'big-app' the possibility to initialize itself.
Bad part: fixed delay in combination with fast or slow PC.
Prefered situation
- Front-end launches the 'big-app' and continues execution when 'big-app' signals its ready to continue.
My question:
What is the best solution for this signalling event. I need no other info than: "I'm ready... go on".
A named pipe looks a bit overkill too me.
With regards,
EizSl
|
|
|
|
|
If the big guy is Windows (not console) app, you should use WaitForInputIdle.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
You can use named Win32 event - see CreateEvent and OpenEvent API functions or CEvent MFC class.
Sonork 100.15206;PavelK
|
|
|
|
|
WM_COPYDATA is hands down the easiest way to communicate between two processes.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Thx for reply Christian,
You mean using the WM_COPYDATA with use of HWND_BROADCAST in SendMessage ?
With regards,
EiSl
|
|
|
|
|
If you don't know the target HWND, yes. I have used it in the past by naming one of my apps so I can use EnumWindows to find it, send it my HWND, and then they can both talk to each other without sending a message to every window on the desktop.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
I want to use raw socket to intercept the ipx packets int the local netware.
I successed in IP, But now I want intercept ipx packets.
Can give me some information about it, Thanks a lot!
Everyone is my teacher!
|
|
|
|
|
hey..
i used CSplitterWnd to split 2 views. The first 1 (CLeftView)i derived from CTreeView and 2nd one (CRightView) from CView. I also created a modal dialog box which i enable from a menu. I want to add new items to my CTreeView derived class(CLeftView). Since it is derived from CTreeView i believe that it should act like tree control. Can any one please explain how new items can be inserted.
|
|
|
|
|
CTreeView has a method CTreeCtrl& GetTreeCtrl(). You fill the items into this control.
Sonork 100.15206;PavelK
|
|
|
|
|
I've tried to do that but that does not work. Here is the code i am using.
void CMainFrame::OnInsertNewroot()
{
CTreeView *pView = (CLeftView2*)GetDlgItem(1);
//CTreeCtrl *pCtrl = pView->GetTreeCtrl();
//(CLeftView2*)CTreeView::GetTreeCtrl();
}
Please comment
|
|
|
|
|
I wonder about the GetDlgItem call - returns it the view pointer really?
I would go for the left view pointer through the document and splitter view.
Sonork 100.15206;PavelK
|
|
|
|
|
How to get the Time & Date from remote WinNT LAN Server
(DomainController) in C++ programm using WinAPI functions or otherway
(not using call to command.com same as: NET TIME \\server_name /SET ).
My programm must run on Win9x, and so I can't use the
NetRemoteTOD API which supplied only in WinNT,
and I can't run DCOMserver on domain controller to
obtain the time and date from it because admin is thery angry.
May be somebody now?
|
|
|
|