Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralWhich .DLL's may be needed by a program compiled by Visual C++ 2008 (free download version)? [modified] Pin
Anthony Appleyard24-Dec-07 10:53
Anthony Appleyard24-Dec-07 10:53 
GeneralRe: Which .DLL's may be needed by a program compiled by Visual C++ 2008 (free download version)? Pin
Bram van Kampen24-Dec-07 13:11
Bram van Kampen24-Dec-07 13:11 
GeneralRe: Which .DLL's may be needed by a program compiled by Visual C++ 2008 (free download version)? Pin
Mark Salsbery24-Dec-07 14:58
Mark Salsbery24-Dec-07 14:58 
GeneralRe: Which .DLL's may be needed by a program compiled by Visual C++ 2008 (free download version)? Pin
Anthony Appleyard24-Dec-07 20:13
Anthony Appleyard24-Dec-07 20:13 
QuestionHow to get DNS addresses from a local pc. Pin
daavena24-Dec-07 3:13
daavena24-Dec-07 3:13 
GeneralDXF solution Pin
Becker24-Dec-07 2:44
Becker24-Dec-07 2:44 
QuestionDWG viewer using VC++ Pin
jakuar24-Dec-07 2:34
sussjakuar24-Dec-07 2:34 
GeneralRe: DWG viewer using VC++ Pin
Joan M29-Dec-07 11:02
professionalJoan M29-Dec-07 11:02 
QuestionCreating views in Top Level MDI Pin
snir_ya24-Dec-07 0:59
snir_ya24-Dec-07 0:59 
QuestionRe: Creating views in Top Level MDI Pin
Nishad S24-Dec-07 2:22
Nishad S24-Dec-07 2:22 
QuestionRe: Creating views in Top Level MDI Pin
snir_ya24-Dec-07 3:10
snir_ya24-Dec-07 3:10 
GeneralRe: Creating views in Top Level MDI Pin
Nishad S24-Dec-07 3:16
Nishad S24-Dec-07 3:16 
GeneralRe: Creating views in Top Level MDI Pin
snir_ya24-Dec-07 5:05
snir_ya24-Dec-07 5:05 
GeneralMy new problem is to copy directory Pin
rajneshmalik23-Dec-07 23:23
rajneshmalik23-Dec-07 23:23 
GeneralRe: My new problem is to copy directory Pin
Nishad S23-Dec-07 23:59
Nishad S23-Dec-07 23:59 
GeneralRe: My new problem is to copy directory Pin
rajneshmalik25-Dec-07 19:42
rajneshmalik25-Dec-07 19:42 

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.