Click here to Skip to main content
16,007,885 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: cannot convert from 'class CString' to 'char [ ] Pin
JoeSox2-Nov-02 19:09
JoeSox2-Nov-02 19:09 
GeneralRe: cannot convert from 'class CString' to 'char [ ] Pin
Stephane Rodriguez.2-Nov-02 22:07
Stephane Rodriguez.2-Nov-02 22:07 
GeneralThread in MFC DLL!!!!!!!!!!!!!!!! Pin
stevenson2-Nov-02 14:20
stevenson2-Nov-02 14:20 
GeneralRe: Thread in MFC DLL!!!!!!!!!!!!!!!! Pin
ian mariano2-Nov-02 14:48
ian mariano2-Nov-02 14:48 
GeneralRe: Thread in MFC DLL!!!!!!!!!!!!!!!! Pin
Michael Dunn2-Nov-02 14:50
sitebuilderMichael Dunn2-Nov-02 14:50 
GeneralRe: Thread in MFC DLL!!!!!!!!!!!!!!!! Pin
ian mariano2-Nov-02 15:03
ian mariano2-Nov-02 15:03 
GeneralRe: Thread in MFC DLL!!!!!!!!!!!!!!!! Pin
stevenson2-Nov-02 19:47
stevenson2-Nov-02 19:47 
GeneralRe: Thread in MFC DLL!!!!!!!!!!!!!!!! Pin
ian mariano2-Nov-02 20:28
ian mariano2-Nov-02 20:28 
You're not seeing the big picture with DLLs. The Main() function you're thinking of is wrapped in calls for loading and unloading the DLL. When a process or thread wishes to use your DLL, it calls (eventually) LoadLibrary. At this point, the DLL entry DllMain() is called. In the case of MFC, it eventually gets to CWinApp::InitInstance. When a process or thread that's using your DLL exits, it "detaches" from the DLL, calling DllMain(), with the detach reason (dwReason in my example earlier.) Eventually, in MFC, ExitInstance will be called, and that's where you'd do the WaitForSingleObject stuff, of course waiting on the thread/process-specific event handle.

It's a bit daunting and confusing at first, but you have to realize that the entry point (DllMain) is your "main" function, and it gets "called" at least twice. Once when the DLL is loaded, and once when it's "let go."

MFC wraps all of this in a CWinApp, where in your implementation you can override the behaviour of InitInstance and ExitInstance. That's where you'd do your "work." InitInstance to create your thread, ExitInstance to signal the thread should "shut down" and where your WaitForSingleObject would take place.

If you were going the ATL or straight Win32 way, you'd write your own DllMain() as I had shown in an earlier response to this thread. It amounts to the same thing: when loaded, create your thread, specific to the process/thread at hand; when unloaded, you stop (hopefully gracefully) the thread, specific to the process/thread at hand.

The "end" of your "main function" is the same, when dwReason is the process/thread detaching, or when ExitInstance() on your CWinApp derived class is called.


"The greatest danger to humanity is humanity without an open mind."
  - Ian Mariano - http://www.ian-space.com/

GeneralShake a window.. Pin
Anonymous2-Nov-02 13:40
Anonymous2-Nov-02 13:40 
GeneralRe: Shake a window.. Pin
ian mariano2-Nov-02 14:58
ian mariano2-Nov-02 14:58 
GeneralRe: Shake a window.. Pin
ian mariano2-Nov-02 15:02
ian mariano2-Nov-02 15:02 
GeneralRe: Shake a window.. Pin
Anonymous2-Nov-02 15:08
Anonymous2-Nov-02 15:08 
QuestionSelecting a region into a DC? Pin
Michael Dunn2-Nov-02 12:16
sitebuilderMichael Dunn2-Nov-02 12:16 
AnswerRe: Selecting a region into a DC? Pin
Paul M Watt2-Nov-02 13:38
mentorPaul M Watt2-Nov-02 13:38 
GeneralFirst-chance Exception in C++ Runtime Pin
Roger Wright2-Nov-02 11:53
professionalRoger Wright2-Nov-02 11:53 
GeneralRe: First-chance Exception in C++ Runtime Pin
Ravi Bhavnani2-Nov-02 14:09
professionalRavi Bhavnani2-Nov-02 14:09 
GeneralRe: First-chance Exception in C++ Runtime Pin
Roger Wright2-Nov-02 18:29
professionalRoger Wright2-Nov-02 18:29 
GeneralCalendar Control Problem Pin
Anonymous2-Nov-02 11:00
Anonymous2-Nov-02 11:00 
GeneralReading binary files with c stdio fread Pin
Anonymous2-Nov-02 10:18
Anonymous2-Nov-02 10:18 
GeneralRe: Reading binary files with c stdio fread Pin
Anders Molin3-Nov-02 2:48
professionalAnders Molin3-Nov-02 2:48 
GeneralSerialization Progress Pin
Ted Christiansen2-Nov-02 9:42
Ted Christiansen2-Nov-02 9:42 
GeneralRe: Serialization Progress Pin
ian mariano2-Nov-02 9:51
ian mariano2-Nov-02 9:51 
GeneralPhilosophical question Pin
Chris Losinger2-Nov-02 9:21
professionalChris Losinger2-Nov-02 9:21 
Generallet me answer my own question... Pin
Chris Losinger2-Nov-02 9:46
professionalChris Losinger2-Nov-02 9:46 
GeneralRe: Philosophical question Pin
ian mariano2-Nov-02 9:42
ian mariano2-Nov-02 9: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.