On Wed, Jun 3, 2009 at 12:45 PM, Igor R <boost.lists@gmail.com> wrote:
> When the SerialPort receive data, pass it to the ATDispatcher that
> raises a signal to the TETRAMoto object that parses the data and raise
> the event (always a signal) to the extern:
>
> asio::serial_port -> SerialPort -> ATDispatcher -> TetraMoto -|-> EXTERN
>
> Now I have to encapsulate this lib into an ActiveX DLL to be used by VB6
> and I have to call CoInitizeEx in the thread that "raise" events..
>
> My question is: where I have to call CoInitizeEx?

You can start the threads with your own thread-function (instead of
io_service::run) that would call CoInitialize(), io_service::run(),
CoUninitialize().


If you don't start the threads from the global scope (after the main has been entered)
you may use the Schwarz-Counter (also known as Nifty-Counter) idiom.

It is well described here: http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter

This is how Jerry Schwarz implemented the thread safe initialization of global iostream objects in STL:
cout, cerr, clog etc.

Regards,
Ovanes