DLL_THREAD_ATTACH/DLL_THREAD_DETACH 
Author Message
 DLL_THREAD_ATTACH/DLL_THREAD_DETACH

I seem to have this problem where in my DLL I am called once for
DLL_PROCESS_ATTACH as expected and then again with DLL_THREAD_ATTACH,
which is also expected.  But when I close my app. I never get called
with DLL_THREAD_DETACH.  As a result I'm leaking memory because I
allocate using LocalAlloc on a per thread basis.  Has anyone
experienced this behaviour?  Am I doing something wrong?

Thanks,

Perry Dillard
Shop Floor Solutions, Inc.



Mon, 31 Jul 2000 03:00:00 GMT  
 DLL_THREAD_ATTACH/DLL_THREAD_DETACH

When you say that your DLL is "caleld once for DLL_PROCESS_ATTACH..." are
you talking about your DLL's CWinApp-derived class' InitInstance or your
DLL's DllMain function???
--
Cheers,
Tom Archer

page: http://tarcher.home.mindspring.com

Quote:

>I seem to have this problem where in my DLL I am called once for
>DLL_PROCESS_ATTACH as expected and then again with DLL_THREAD_ATTACH,
>which is also expected.  But when I close my app. I never get called
>with DLL_THREAD_DETACH.  As a result I'm leaking memory because I
>allocate using LocalAlloc on a per thread basis.  Has anyone
>experienced this behaviour?  Am I doing something wrong?

>Thanks,

>Perry Dillard
>Shop Floor Solutions, Inc.



Fri, 04 Aug 2000 03:00:00 GMT  
 DLL_THREAD_ATTACH/DLL_THREAD_DETACH

I tried to email this to you, but for some reason it bounced...

You mentioned that your DLL isn't an MFC Extension DLL, but have you tried
creating a "regular DLL" using AppWizard?

As you probably know, the AppWizard generated regular DLL has an
InitInstance that is called only when a *process* attaches and an
ExitInstance that is called only when a *process* detaches. This causes a
problem for people like yourself who need to know when threads attach and
detach.

In order to overcome this, you will have to replace the MFC implementation
of DllMain . It's been a while since I've done this, but the jist of it is
this.

create regular dll (using appwizard)
copy mfc's dllmodul.cpp into project's source folder
add your dllmodul.cpp to the project
make necessary modifications to dllmain
make project (your dllmodul.cpp will be used)

Note that Microsoft only recommends this approach in cases where it is
absolutely necessary. In fact, the case you described is exactly the example
they give on creating your own DllMain with an AppWizard generated regular
DLL.

HTH,
Tom Archer

Quote:

>I seem to have this problem where in my DLL I am called once for
>DLL_PROCESS_ATTACH as expected and then again with DLL_THREAD_ATTACH,
>which is also expected.  But when I close my app. I never get called
>with DLL_THREAD_DETACH.  As a result I'm leaking memory because I
>allocate using LocalAlloc on a per thread basis.  Has anyone
>experienced this behaviour?  Am I doing something wrong?

>Thanks,

>Perry Dillard
>Shop Floor Solutions, Inc.



Tue, 08 Aug 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. bufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbufferoverrunbuf

2. CABLE BOX DESCRAMBLER PLANS ((LEGAL)),.,.,,.,,,,,,,,,,,,,,,.,.,.,,,,,,,,,,,,,,,,,,,,,,,,.,,,,,,,,.,.,,,,,,,,,,,.,,,,,,, 8077

3. DLL_THREAD_DETACH and DLL_THREAD_ATTACH

4. error analysis/handling/detecting/reporting/preventing/recovery/reproduce/debug

5. Printing Help please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

6. alt.comp.databases,comp.databases,comp.databases.ms-sqlserver

7. C:\Workshop\downloads\samples\internet\ie55\RenderBehave\renderproject

8. ? HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\LEGACY_

9. AFX_XXXDOC_H__E89EEE8A_EADC_11D1_9403_00A0FFFF80BB__INCLUDED_

10. Unhandled Exception: System.Configuration.ConfigurationException: Could not create System Configuration.NameValueSectionHandler, System

11. JFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) in C# (.NET - openFileDialog)

 

 
Powered by phpBB® Forum Software