¿Debe inicializar el COM (fuera de proceso) dentro del objeto creado?

I created a Windows NT service, which exports a COM interface using ATL (out-of-proc COM), I do API calls CoInitializeEx (0, COINIT_MULTITHREADED) in the Ctor(), CoUninitialize () in the Dtor() of the class of my object?

La lectura Fashionable App Designers Agree: The Free Threading Model is What's Hot This Fall y Give ActiveX-based Web Pages a Boost with the Apartment Threading Model did nothing to clarify.

My ATL project have declaration of :


preguntado el 10 de marzo de 12 a las 12:03

1 Respuestas

For an out-of-process ATL server that's already taken care of by the CAtlExeModuleT constructor. It will call InitializeCom() in its constructor. When you've #defined _ATL_FREE_THREADED, that will automatically produce a call to CoInitializeEx(NULL, COINIT_MULTITHREADED), as you'd expect. The code is easy to find back in vc/atlmfc/include/atlbase.h

Interface method calls will be made from the stub by an RPC thread, the actual thread that makes the call is entirely unpredictable. Pretty dangerous too because RPC recycles threads and the calls are often made by the same thread. But not always, depending on how many concurrent calls are being processed. The burden of supporting free threading is to ensure that your code is entirely thread-safe. If you have any bugs of the deadlock or threading race kind or rely on a synchronization object that has thread-affinity like Mutex across multiple calls then they won't ruin your day until the server gets heavily loaded. Be sure to test this.

respondido 10 mar '12, 13:03

Yes, the code is highly concurrent, but is well synchronized. His help was enlightening. Thank you. - lsalamon

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.