Click here to Skip to main content
15,891,136 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modeless Dialog Disappearing Pin
aei_totten1-Jun-06 4:18
aei_totten1-Jun-06 4:18 
AnswerRe: Modeless Dialog Disappearing Pin
David Crow1-Jun-06 4:39
David Crow1-Jun-06 4:39 
GeneralRe: Modeless Dialog Disappearing Pin
aei_totten1-Jun-06 6:19
aei_totten1-Jun-06 6:19 
QuestionActive document Pin
Luksky31-May-06 10:17
Luksky31-May-06 10:17 
AnswerRe: Active document Pin
Nibu babu thomas31-May-06 19:26
Nibu babu thomas31-May-06 19:26 
GeneralRe: Active document Pin
Luksky1-Jun-06 7:49
Luksky1-Jun-06 7:49 
QuestionLearning C++ -- from a C# point of view Pin
matiasdk31-May-06 10:08
matiasdk31-May-06 10:08 
AnswerRe: Learning C++ -- from a C# point of view Pin
Zac Howland31-May-06 10:19
Zac Howland31-May-06 10:19 
QuestionCan i save font in my MFC application? Pin
Immunity1831-May-06 10:07
Immunity1831-May-06 10:07 
AnswerRe: Can i save font in my MFC application? Pin
Benoy Bose31-May-06 19:00
Benoy Bose31-May-06 19:00 
GeneralRe: Can i save font in my MFC application? Pin
NiceNaidu31-May-06 20:10
NiceNaidu31-May-06 20:10 
Questionenumport problem Pin
wang200731-May-06 9:57
wang200731-May-06 9:57 
AnswerRe: enumport problem Pin
David Crow31-May-06 10:11
David Crow31-May-06 10:11 
AnswerRe: enumport problem Pin
NiceNaidu31-May-06 19:32
NiceNaidu31-May-06 19:32 
QuestionSocket Class to use with MFC [modified] Pin
SPowers31-May-06 9:48
SPowers31-May-06 9:48 
AnswerRe: Socket Class to use with MFC [modified] Pin
Zac Howland31-May-06 10:13
Zac Howland31-May-06 10:13 
GeneralRe: Socket Class to use with MFC [modified] Pin
SPowers31-May-06 10:19
SPowers31-May-06 10:19 
GeneralRe: Socket Class to use with MFC [modified] Pin
Zac Howland31-May-06 10:37
Zac Howland31-May-06 10:37 
Questionusing a dll to run the graphics of a scr Pin
reasley31-May-06 9:37
reasley31-May-06 9:37 
AnswerRe: using a dll to run the graphics of a scr Pin
David Crow31-May-06 10:10
David Crow31-May-06 10:10 
QuestionRe: using a dll to run the graphics of a scr Pin
reasley31-May-06 10:16
reasley31-May-06 10:16 
QuestionRe: using a dll to run the graphics of a scr Pin
David Crow31-May-06 10:29
David Crow31-May-06 10:29 
AnswerRe: using a dll to run the graphics of a scr Pin
reasley31-May-06 10:31
reasley31-May-06 10:31 
AnswerRe: using a dll to run the graphics of a scr [modified] Pin
Zac Howland31-May-06 10:30
Zac Howland31-May-06 10:30 
reasley wrote:
Thanks. I just found that function, finally, on the MSDN site. One question I have on this function though is that if I use this function as if it were a WinMain function and put a loop in it to process graphics animations, is there a way to gracefully close the dll when the screen saver turns off? For instance, when the mouse is moved the screen saver should exit, but if the dll has a graphics processing loop in it's DllMain function, will the screen saver still receive the exit notification? And if it does, I would guess that then I would want to call the FreeLibrary function to release the dll, or possibly the FreeLibraryAndExitThread function so that it closes the screen saver as well. But will I be able to release the resources created by the dll or is it done automatically when the FreeLibary function is called? I did not see any type of "WinProc" funciton for the dll so that I can process messages.


For what you want, you don't want to use DLLMain. DllMain basically initializes the dll. You can pretty much leave the default code the wizard gives you in it alone. What you will want is to create a function that will spawn a thread to do operations. That thread will need to keep an event handle and check it periodically to see if it needs to exit. To cause the thread to exit, you will call a separate method that will trigger the event.

The basic flow will look like this:
In the main application (pseudo-code)

<br />
// Initialize my application<br />
// Load my Dll<br />
LoadLibrary("MyDll.dll")<br />
// get function pointers to the start and stop methods<br />
MyStartFunc = GetProcAddress("Start")<br />
MyStopFunc = GetProcAddress("Stop")<br />
<br />
// start main graphic loop<br />
MyStartFunc()<br />
<br />
// after a while, user presses a button, moves mouse, whatever<br />
MyStopFunc()<br />
<br />
// free library<br />
FreeLibrary(MyDll)<br />


In the Dll

<br />
MyEvent = NULL<br />
<br />
function Start<br />
[<br />
   MyEvent = CreateEvent()<br />
   StartThread(MyGraphicLoop)<br />
]<br />
<br />
function MyGraphicLoop<br />
[<br />
   if (MyEvent is Triggered)<br />
      exit<br />
   else<br />
      RenderGraphics()<br />
]<br />
<br />
function Stop<br />
[<br />
   TriggerEvent(MyEvent)<br />
]<br />


If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

-- modified at 16:31 Wednesday 31st May, 2006
GeneralRe: using a dll to run the graphics of a scr [modified] Pin
reasley31-May-06 10:35
reasley31-May-06 10:35 

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.