Click here to Skip to main content
15,907,910 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Desktop_.ini file is getting created in InstallShield Pin
Kiran Pinjala26-Dec-07 1:38
Kiran Pinjala26-Dec-07 1:38 
GeneralError in MD5Init() Function Pin
Developer61124-Dec-07 23:40
Developer61124-Dec-07 23:40 
GeneralRe: Error in MD5Init() Function Pin
CPallini25-Dec-07 3:21
mveCPallini25-Dec-07 3:21 
GeneralRe: Error in MD5Init() Function Pin
Developer61126-Dec-07 0:48
Developer61126-Dec-07 0:48 
QuestionHow to search a Subitem in list control? Pin
Rad.Krish24-Dec-07 23:32
Rad.Krish24-Dec-07 23:32 
GeneralRe: How to search a Subitem in list control? Pin
CPallini25-Dec-07 2:55
mveCPallini25-Dec-07 2:55 
GeneralLarge File Processing Pin
Sangeetha_J24-Dec-07 23:10
Sangeetha_J24-Dec-07 23:10 
GeneralRe: Large File Processing Pin
CPallini24-Dec-07 23:39
mveCPallini24-Dec-07 23:39 
GeneralRe: Large File Processing Pin
Sangeetha_J24-Dec-07 23:54
Sangeetha_J24-Dec-07 23:54 
GeneralRe: Large File Processing Pin
CPallini25-Dec-07 2:43
mveCPallini25-Dec-07 2:43 
GeneralRe: Large File Processing Pin
Sangeetha_J25-Dec-07 16:34
Sangeetha_J25-Dec-07 16:34 
GeneralRe: Large File Processing Pin
kagdizuber26-Dec-07 5:23
kagdizuber26-Dec-07 5:23 
GeneralRe: Large File Processing Pin
Sangeetha_J26-Dec-07 17:18
Sangeetha_J26-Dec-07 17:18 
QuestionWhat about the efficency of DrawImage and coordinate transformation in GDI+ [modified] Pin
followait24-Dec-07 19:39
followait24-Dec-07 19:39 
QuestionDLLs for MFC Activex Controll Pin
manish.patel24-Dec-07 18:39
manish.patel24-Dec-07 18:39 
GeneralRe: DLLs for MFC Activex Controll Pin
_AnsHUMAN_ 24-Dec-07 20:48
_AnsHUMAN_ 24-Dec-07 20:48 
GeneralRe: DLLs for MFC Activex Controll Pin
manish.patel24-Dec-07 20:52
manish.patel24-Dec-07 20:52 
GeneralRe: DLLs for MFC Activex Controll Pin
_AnsHUMAN_ 24-Dec-07 20:54
_AnsHUMAN_ 24-Dec-07 20:54 
QuestionHow to use GetBitmapBits( ) correctly Pin
Chen-XuNuo24-Dec-07 17:20
Chen-XuNuo24-Dec-07 17:20 
AnswerRe: How to use GetBitmapBits( ) correctly Pin
Anthony Appleyard24-Dec-07 20:21
Anthony Appleyard24-Dec-07 20:21 
GeneralDLL_THREAD_ATTACH and The Tls Api,s Pin
ForNow24-Dec-07 16:03
ForNow24-Dec-07 16:03 
GeneralRe: DLL_THREAD_ATTACH and The Tls Api,s Pin
peterchen24-Dec-07 20:52
peterchen24-Dec-07 20:52 
GeneralRe: DLL_THREAD_ATTACH and The Tls Api,s Pin
ForNow24-Dec-07 21:48
ForNow24-Dec-07 21:48 
GeneralRe: DLL_THREAD_ATTACH and The Tls Api,s Pin
peterchen25-Dec-07 5:29
peterchen25-Dec-07 5:29 
Yes, ypou can. In fact, you don't even need to handle the DLL_THREAD_ATTACH notification:

static int slot = TlsAlloc();  // (1)

CMyState * GetThreadState()
{
  INT_PTR value = TlsGetValue(slot);
  if (value == 0) // no object was created yet for this thread, create a new one and add it:
  {
    CMyState * state = new CMyState(); // (2)
    TlsSetValue(slot, (INT_PTR) state);
    return state;
  }
  return (CMyState *) value;
}


Note that this sample omits all error handling. Especially in (1) TLS slots may already be exhausted, in which case you need to fail gracefully. TLS slots are a very limited resource, so you should use one and only one and only when you really need it. So you'd better design an extensible data structure for your use (rule: play nice wiht others). Also, (2) may throw or return a NULL depending on your memory error handlign settings.

You must, however, handle DLL_THREAD_DETACH (or another "thread is terminating" mechanism) to free the objects you created.

We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
My first real C# project | Linkify!| FoldWithUs! | sighist


GeneralRe: DLL_THREAD_ATTACH and The Tls Api,s Pin
ForNow25-Dec-07 7:00
ForNow25-Dec-07 7:00 

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.