|
A thread created by using AfxBeginThread(RUNTIME_CLASS(CClientHandler));
can be end/destroyed by using AfxEndThread(..) , would it be called from inside of same thread.
If the AfxEndThread will end the thread then would the object created inside of that thread will also be destroyed?
Thanks
Regards.
|
|
|
|
|
AfxEndThread must be called from within the thread you wish to stop.
Steve
|
|
|
|
|
would this stop release all the memory that the thread and its members objects have occupied
Regards.
|
|
|
|
|
IMHO, the most cleaner way to exit a thread is simply to return from the thread. For example, if you have a loop within the thread, you can simply use a flag to signalate when the thread must exit. This flag can be set by another thread (by using thread-safe methods, like CCriticalSection).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
A thread can be terminated in four ways:
1)The thread function returns. (This is highly recommended.)
2)The thread kills itself by calling the ExitThread function. (Avoid this method.)
3)A thread in the same or in another process calls the TerminateThread function. (Avoid this method.)
4)The process containing the thread terminates. (Avoid this method.)
Option 1 ensures that all thread resources are cleaned up properly. Any and all C++ objects created in your thread function will be destroyed properly via their destructors.
The operating system will properly free the memory used by the thread's stack.
The system will set the thread's exit code (maintained in the thread's kernel object) to your thread function's return value.
The system will decrement the usage count of the thread's kernel object.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
See here.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hi Friends,
what is the best way to convert a CString to char* , using GetBuffer or using
operator LPCTSTR ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Use GetBuffer (). Avoid Typecasting when you need to change or modify the value in the string.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 2:55 Thursday 1st June, 2006
|
|
|
|
|
I dont think that there is problem in type casting.
It is the operator overloaded in CString.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
You don't need an explicit cast to use CString 's operator LPCTSTR . Here's an example:
CString s("Hello world!");
const char *pString = s;
You don't need a static_cast<LPCTSTR>(s) or a (LPCTSTR)s . Also note that this isn't a cast in the normal sense; it's a user defined conversion operator.
Don't use GetBuffer unless you need to make modifications.
In short here are the rules:
- If you need a const pointer do nothing: the compiler will work out what to do.
- If you need non-const pointer use GetBuffer .
Steve
|
|
|
|
|
LPCTSTR
for get buffer, u may have to call release buffer.
if it is doing in a large source code base, and if miss a release buffer it will be hard to find and fix it.
u can modify a CString content by calling many other services provided by the same class.
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
u r right Sarath,
But the problem is GetBuffer takes the parameter for length ,
So i need to call GetLength and test whether the length is greater than 0,
So, this is a big process.
if i use LPCTSTR,
it is returning const char *(void) but i when i require const char*, this is not going to help me.
Is there any alternate to these two???
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
Sorry for the late reply my connection got disconnected
it is possible to do in this way
its working for me.. but I donno whether it is the right way or not
CString strText("test");<br />
LPSTR lpStr = (LPSTR)(LPCSTR) strText;
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
Depends on what you want to do with the string.
If you want to modify it, use GetBuffer or GetBufferSetLength , which returns an LPTSTR (not const). Just remember to ReleaseBuffer .
If you're not modifying the string, you can use operator LPCTSTR , since it's const.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
if you want to convert to char* , use (LPSTR)
if you want to convert to TCHAR* , use (LPTSTR)
if you want to convert to const char* , use (LPCSTR)
if you want to convert to const TCHAR* , use (LPCTSTR)
use GetBuffer() if you want to perform some modifications on the string...
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
U mean type casting the CString ??
CString strTest;
To convert this to const char* ,can i use (LPCSTR)strTest ??
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
|
NiceNaidu wrote: CString strTest;
To convert this to const char* ,can i use (LPCSTR)strTest ??
const TCHAR *pStr = strTest; .
Nibu thomas
A Developer
Programming tips[^] My site[^]
|
|
|
|
|
NiceNaiduTo convert this to const char* ,can i use (LPCSTR)strTest ??
Yes, but the cast is unnecessary. Others have explained this.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
neither of those two methos r correct, because both of them return LPTSTR OR LPTSTR, but they r different to char *, when UNICODE is defined beforehand, then LPTSTR equiles w_char *. so I think u should judge if the UNICODE is defined to decide how to convert to char *
life is like a box of chocolate,you never know what you r going to get.
|
|
|
|
|
Hai,
I am to use a .h file in .c file. In the .h file i have to give a definition for a c++ class. I have to use that .h file in the .c file not .cpp file. how can i use that. To say in simple words, i have to use c++ code in a c code( that too in linux) Can any one help me???
Any help appreciated
Saravana Kumar
|
|
|
|
|
C does not support Class concept,
So replace all the Classes with structures and try.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
|
whhich compiler u r using ?
if u r using a C compiler make the class definition in
#ifdef __cplusplus
// class Definition
#endif
SaRath
"D on't blindly follow rules you read somewhere without verifying that it makes sense for your situation!"
|
|
|
|
|
Ya Thanks Sarath. It works i am to use cc compiler.
Saravana Kumar
|
|
|
|