07-20-2005 10:41 AM
07-20-2005 02:04 PM
07-20-2005 02:36 PM
07-20-2005 03:45 PM
CNiTimer calls your callback in a thread that CNiTimer creates and manages. This thread is different than your application main thread. You are controlling Excel through COM. The COM libraries require that you initialize COM in every thread that calls into them. You don't have to do this explicitly in your application main thread because MFC handles this for you automatically in the application startup code.
I should have mentioned before that Measurement Studio includes a class you can use to initialize COM. The advantage of the class is that it unitializes COM when the class goes out of scope, so you don't have to explicitly call CoUninitialize (even if your callback exits because of an exception).
Just add the following declaration to the top of your callback function:
CNiComInitialize comInitialize(CNiComInitialize::Apartment);
I also recommend that you add a try/catch block and handle any exceptions within the callback rather than allowing the exception to propagate to the CNiTimer code.
07-25-2005 09:20 AM
Thanks for the info. I'll add that to my callback.