|
There are some ways to stop a thread .
1) AfxEndThread()
2) TerminateThread()
3) _endthreadex()
IT's not safe to terminate a thread using the above functions.
You should check for a condition to be true. Whenever that condition turns true and the thread is still running, use return to exit safely from the thread function.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
zouchao1112 wrote: stop a work thread without waiting for it
Bad design. Why would you want to do this ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
|
|
|
|
|
zouchao1112 wrote: if I want to stop a work thread without waiting for it, how can I terminate it safely...
You can't. While TerminateThread() does indeed terminate a thread, it does so immediately and the thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating. TerminateThread() is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread() only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The general method is for the thread to periodically check a value and terminate if it matches some criteria. The simplest method is to check a bool and cleanup/exit if it goes to false. The preferred method is to use a manual set event handle and check it with a timeout of zero; if it goes signaled, I then can cleanup/exit. (The big advantage of the latter is that threads are often in a waiting state. With an event handle, you can do a WaitForMultipleObjects .)
(You would then set the "closing" event, and wait for say 5 seconds on the thread handle. If it doesn't close, log an event and call TerminateThread().)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
save the handle to the thread when you create it:
hthread = CreateThread ( 0, 0, MyThread, this, 0, 0 );
then terminate it like this:
TerminateThread ( hthread, 0 );
Just livin a dream.. dont wake me!
|
|
|
|
|
hello friends!
I had been told that we can not have resourses(.RC) like string table with our Win32 static Library. And if we had , then we hav to include .rc file along with the library file in an application using them.
Is it true! i yes is there any other way(except .DLL).
|
|
|
|
|
You have either been misinformed, or simply misunderstood. Resource-only DLLs exist and are quite common. Whether that DLL is implicitly (static) or explicitly (dynamic) linked to is up to the other application and has no bearing on what the DLL can contain.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
Thx for the replies.
But i am totally confused now.
Can anybody elaborate more on this? can i have resource .rc along with .LIB file.???
|
|
|
|
|
A LIB file is platform independent. It is a set of routines, already compiled into machine language, and assembled together. Since they are platform independent they cannot contain any specific platform dependent information, like Windows resources. A LIB is a compiler loadable file.
A DLL, on the other hand, is a set of routines already compiled into machine language, assembled together, and wrapped into a platform dependent file. So, they can contain Windows resources, since DLL's are Windows format files. In fact, a DLL is a LIB with platform specific wrapping packed into an operating system loadable file.
The diference is in the last compilation process, the wrapping. That process also makes the closed wrapped form not usable statically (because DLL's are always dynamic, by definition). So, if your executable uses the code from a DLL then the DLL must be also made available (as a separate file) for Windows to load it when the executable is loaded (there are several ways to acomplish this).
A LIB file is not closed (it is not wrapped), so it may be placed inside the executable. In fact, as the compiler is building the EXE (or DLL) it can (and does) get code from various LIB files and puts it inside the EXE (or DLL). In all this process the resources have to come from somwhere other than LIB's.
There is a way to get around this. A LIB file is designed to contain both code and data. So, one trick is to declare a global variable, of type char [], that contains all the bytes you need your lib to have. You could write a simple program to convert any file into the corresponding C++ form. This program would do the following:
Read bytes of file "test.rc":
0x44 0x87 0x13 0x00 0xfa 0x60...
Generate the appropriate C/C++ file:
char test_rc[]={
0x44, 0x87, 0x13, 0x00, 0xfa, 0x60, ...
};
Then you could, at run time, obtain the buffer "test_rc" and its size "sizeof(test_rc)". This is a perfectly legal thing to do with LIB's. You could also write this data to a file, at run-time, for whatever purpose you like. My webservers work like this, the HTML pages are all contained inside LIB files, and I generate executables, DLL's, SO's (for LINUX), etc, all from the same LIB files. The advantage of this is that the executables are distributed without any additional garbage and are ready to run. Also, it becomes very difucult for someone to modify the pages I embbed in the executables 8because they are not Windows resources, and are, instead, part of the machine language LIB code).
However, I don't know how you could use this RC file in Windows at run-time... I know that you may specify resources at run-time when you use Win32 API functions, but with MFC I just don't know.
I hope this helps.
Rilhas
|
|
|
|
|
Hi rihas!
Thx a lot for the reply!
It made clear lots of things for me.
Thx again!
|
|
|
|
|
Hi All,
O.K so here is the problem. I'm trying to associate a process with a program that is currently running. i.e lets say winamp is running, and I want to monitor winamp, but I don't want to restart the process / kill the process, I want the new process to be associated with that one.
Process^ TEST = gcnew Process();
array<process^>^StartupApp = TEST ->GetProcesses();
TEST ->StartInfo->FileName = "winamp.exe";
CardSystem->StartInfo->WindowStyle = ProcessWindowStyle::Normal;
CardSystem->Start();
But see the above code will start a new session of winamp. I just want to assign the values of the process winamp to the process TEST.
If anyone could help or point me to a site on the net.
Thanx alot
Programm3r
|
|
|
|
|
Well, since this is the VC++ forum, and not the managed one, I would suggest using OpenProcess(...) to get a handle to the running instance of WinAmp. That is where I would start.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
one Managed C++/CLI
see James R. Twine answer and you can use CreateProcess
whitesky
|
|
|
|
|
Is it possible for me to link an SDI in my dialog based application? For example, when a button in the dialog is clicked, an SDI comes up.
I've tried to 'File->Add->New Project' and added an SDI project into my current project but i have no idea how to link them up.
|
|
|
|
|
Probably you can go the otherway around :-
1.First Create an SDI application hide the mainframe .
2.Bring the Dialog to the Foreground.
3.On Button click hide the dialog and bring the framewindow to the front.
Regards,
FarPointer
Blog:FARPOINTER
|
|
|
|
|
while you click the button, you can
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMyMainFrm), // main SDI frame window
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
m_pFormTemplate = pDocTemplate;
as usual in you button handler and show the MainFrame.
|
|
|
|
|
Sorry but I don't quite get what is 'AddDocTemplate' and 'm_pFormTemplate'.
|
|
|
|
|
well, if you create a project that is based on single document/view, you can see the code in CMyWinApp::InitInstance().
|
|
|
|
|
Hi to all
sorry if it's not the right place to ask this quastion!
I'm member of team wich works on rescue robots.our robot has laser scaner
and with the data it gives we can make maps.I want to know how can we make real time 3D model of an arena?or does any real time 3D model making example exist!
Best regards
Reza Razavi
|
|
|
|
|
|
They give informations about an anknown place.The data comes from the robot wich is in a mission and tells that where the wall's and other things are located!I should make a 3D model of that place and update it every time that robot sends new information and save it as a file that you can open it later and be able to surf on like a 3D game.So you think I can do it by learning opengl?I know a little about DirectX only worked with DirecInput.Can I do this with Direct3D??Wich one is the simple way ?is any example wich is close to what I want available?
Regards
Reza Razavi
|
|
|
|
|
Hello everyone,
I use VC 7 (Visual Studio.Net 2003) created a static lib, then I use VC6 to link with it in an application, there are some errors during link. Here is the source file of the lib,
<br />
int foo()<br />
{<br />
return 2008;<br />
}<br />
Here is the header of the lib file,
<br />
int foo();<br />
Here is the application using the static lib,
<br />
#include "foo.h"<br />
<br />
int main()<br />
{<br />
int a = foo();<br />
<br />
return 0;<br />
}<br />
When building the lib using VC7, there are no errors and the static lib is generated. When building the application and link it with the static lib, there are errors,
<br />
--------------------Configuration: VC6VC7lib - Win32 Debug--------------------<br />
Linking...<br />
VC7_static_lib.lib(foo.obj) : fatal error LNK1190: invalid fixup found, type 0x000C<br />
Error executing link.exe.<br />
<br />
VC6VC7lib.exe - 1 error(s), 0 warning(s)<br />
I can not find any useful information from MSDN. Could anyone help please -- how to use VC6 link a static library generated by VC7?
thanks in advance,
George
-- modified at 7:33 Tuesday 27th June, 2006
|
|
|
|
|
Maybe the older linker simply does not understand the new format of *.lib library files?
|
|
|
|
|
Thank you Viorel!
Your description is reasonable. Do you have any solutions? Maybe there are some methods to build static lib in VC7 for VC6 application?
regards,
George
|
|
|
|