Hi ootbt08,Quote from ootbt08:
I'm wondering if anyone would have a sample dll that they would be able to share that would show the basics of hooking into Anvil and generating a few threads.
Welcome to the thread.
If you are following the examples then your dialog is an MFC dialog, correct? When you created this dialog, it actually hooked into the main windows thread of Anvil, and MFC will gracefully unhook it as well when you shut down your application. So as far as hooking, you're good to go. All of the Anvil API commands can be executed in your dialog's methods, as each method is run in the main Anvil thread.
As for the threading, it sounds like what you want is to create some background worker threads, right? In Windows vernacular, you have two kinds of threads, "worker threads" which have no message pump, i.e. they're just basically a subroutine that runs in a separate thread until the routine exits, and "UI threads" which have a message pump and can receive messages from Windows or other threads. Note that UI threads do not require a visible window associated with them, although they can support a window, unlike worker threads.
You can use either kind of thread as a background thread. The decision point is what kind of communication do you need between threads? In my case, I tend to use background threads that are event driven, so I create a UI thread derived from CWinThread. Then you can post messages to the thread using PostThreadMessage, i.e. when the data you've subscribed to changes. To execute the API functions, you need to post a message to your main dialog (which is in the Anvil thread). If you want to do this synchronously, you will then need to wait until the routine completes. I do this using events. (It's not wise to use SendMessage across threads.)
I know this is a rather high level overview, but hopefully it will point you in the right direction. I'm not able to get to my code now, but I might be able to throw something together that I could share later today or tomorrow. I was actually thinking about writing a generic multithreaded framework that would help people get started with using multithreaded Anvil extension DLL's... It might help to see a concrete example of one implementation of multithreading and synchronization.
