mfc >> DLL - Calling application notification upon destroy

by Joe Estock » Sun, 30 Nov 2003 02:49:12 GMT

Is there any way to detect when an application that is calling my dll is
about to be destroyed?

I need to close several files if the calling application has not done so,
therefore I need to detect when the calling application is about to be
destroyed and clean up the files and variables I have used in the dll.




mfc >> DLL - Calling application notification upon destroy

by Tom Jones » Sun, 30 Nov 2003 06:11:31 GMT


You need to implement DllMain, the handle your cleanup tasks when you
receive a PROCESS_DETACH notification.

Check out:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_initialize_non.2d.mfc_dlls.asp








mfc >> DLL - Calling application notification upon destroy

by John Smith » Sun, 30 Nov 2003 18:53:21 GMT

Yes and no - read very CAREFULLY what you may and more important may NOT do
on PROCESS_ATTACH/DETACH...



http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_initialize_non.2d.mfc_dlls.asp


so,




DLL - Calling application notification upon destroy

by Tom Jones » Mon, 01 Dec 2003 04:58:15 GMT

Very helpful John - why do people feel the need to interject without
actually helping the person who originally asked the question?

Joe, what John is referring to is that while your DllMain function is
executing a special critical section, normally referred to as the "process
critical section" is held. So certain things, anything that would cause
DllMain to be called again for example, cause very difficult to debug
deadlocks.

Here is an excellent explaination of the problem by Matt Pietrek:

http://www.microsoft.com/msj/archive/S220.aspx

TJ



do


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_initialize_non.2d.mfc_dlls.asp


is




Similar Threads

1. URGENT: Need to call VB6 DLL from C# .net application without referencing VB6 DLL

Guys,
I am using c# to call some DLL. Here is my situation, I tried to create
reference to this dll in my project and I am able to call this dll
successfully, but when actual dll is upgraded to new version it is
giving COM exception like CLSID is not registered. Because of this I am
having some admin problems. I want a solution without referencing the
dll I need to call the original DLL OR how to overcome this situation
if I reference the DLL in the project.

Could someone help me out what I can do to solve this issue?


Any help would be greatly appreciated

Tx,
csharpguy

2. vc++8.0 bug: access violtation upon any call of any CImageList methods

3. STA behaves like MTA upon method call

Hi,

My program contains three parts:
    Part A) in-process COM server created in STA;
    Part B) in-process COM server created in MTA;
    Part C) another out-process COM server created in part A. The
other process uses STA.
Part A registers an event sink from the COM server in part B.

Problem happens when a method in part A invokes a lengthy method of
part C. Before C's method returns, part B happens to fire a COM event.
>From my log files I can see that part A starts to execute the event
sink, before A's method returns. The thread that executes A's method
and the thread that executes the event sink have the same ID. After
the event sink is finished, the same thread resumes from A's method,
that is the invocation of C's method.

The log shows following are done in sequence by the same thread of A:
- enter A's method
-   invoke C's method
-     receive B's event
-     process B's event
-   after invoking C's method
- leave A's method

I guess this is because method call in STA is via windows messages,
although I'm not sure how exactly this could happen. This caused my
event processing to behave incorrectly because it relied on some flags
set before leaving A's method. As C's method took quite some time, B's
event often fired around that time.

How to overcome that? Is there a way to ensure that the STA completes
a method before executing the next?

Thanks.

best regards,
xudong

4. vc++8.0 bug: access violtation upon any call of any CImageList methods

5. How can I call a function from an MFC Dialog upon start up

How can I call a function from an MFC Dialog upon startup without
having to call it from the OnPaint() method?.  I want the dialog to
complete the OnPaint() and then call a function?.  I am needing an
Install Dialog that has a Status bar and automatically executes
without any user interaction.  So far I managed to get a dialog
working with the status bar and by calling my install function from
the OnPaint() method, but ofcourse that is not the way to program!. 
Thanks for any solution in advance.

Robert Carlson
Aqweeva Software
 XXXX@XXXXX.COM 

6. SetClipboard crashing upon 2nd call with XP

7. Calling function depending upon MACRO value

Hi,

I need to write a MACRO which helps to call different functions
depending upon it's value say On or OFF. If its' value is ON the
function1 should get called and if value is OFF function2 gets called .

It's like same as assert gets executed when NDEBUG is not defined at
the start of code. If NDEBUG is defined assert doesn't gets called at
all.

Thanks
dhesi

8. Virtual calls upon destruction