Click here to Skip to main content
15,881,248 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
QuestionVisual Studio 2005, Multithreading option? Pin
Yonggoo31-May-06 9:02
Yonggoo31-May-06 9:02 
AnswerRe: Visual Studio 2005, Multithreading option? Pin
Cedric Moonen31-May-06 9:26
Cedric Moonen31-May-06 9:26 
AnswerRe: Visual Studio 2005, Multithreading option? Pin
Zac Howland31-May-06 10:04
Zac Howland31-May-06 10:04 
AnswerRe: Visual Studio 2005, Multithreading option? [modified] Pin
Yonggoo31-May-06 10:56
Yonggoo31-May-06 10:56 
QuestionPrecision Timing? Sleep(1)=15 millisecs !! Pin
Robert Palma Jr.31-May-06 8:57
Robert Palma Jr.31-May-06 8:57 
AnswerRe: Precision Timing? Sleep(1)=15 millisecs !! Pin
David Crow31-May-06 9:16
David Crow31-May-06 9:16 
AnswerRe: Precision Timing? Sleep(1)=15 millisecs !! Pin
Zac Howland31-May-06 9:23
Zac Howland31-May-06 9:23 
QuestionThreads Pin
Anthony988731-May-06 8:56
Anthony988731-May-06 8:56 
AnswerRe: Threads Pin
valikac31-May-06 10:04
valikac31-May-06 10:04 
GeneralRe: Threads Pin
Anthony988731-May-06 14:42
Anthony988731-May-06 14:42 
GeneralRe: Threads Pin
valikac31-May-06 14:46
valikac31-May-06 14:46 
QuestionGetting screen coordinated from a window [modified] Pin
Ista31-May-06 8:50
Ista31-May-06 8:50 
QuestionRe: Getting screen coordinated from a window [modified] Pin
David Crow31-May-06 9:13
David Crow31-May-06 9:13 
AnswerRe: Getting screen coordinated from a window [modified] Pin
Ista31-May-06 9:18
Ista31-May-06 9:18 
GeneralRe: Getting screen coordinated from a window [modified] Pin
Zac Howland31-May-06 10:01
Zac Howland31-May-06 10:01 
QuestionArray of images [modified] Pin
sclore31-May-06 8:35
sclore31-May-06 8: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.