Changing the MFC Dialog from STA to MTA?

I am working on an API that has some COM interfaces. The problem is that the API communicates through an interface that must be implemented by a project that loads this API. Therefore, if I used the API, I would upload it to my project and create a class that will implement the methods that the API will call to notify me of some things or pass me the results.

This obviously becomes a nightmare. In addition, since there are also some intermediate objects that pass calls through the API from different plugins and managers to all objects that implement methods for calling notifications that have registered in the notification API, this is out of control of complexity.

I thought, in order to shorten the work that the person who loads the API should do if the API should follow a free streaming model, is it possible that a class generated by MFC, such as a dialog for implementing a COM interface, is needed for notifications? Keep in mind that such an object must be converted to IStream and returned to the interface at the end of the API so that the API can call these methods.

As far as I know, the default MFC dialogs are STAs. Is there a way to get them to change or start in MTA? Is this even legal from a COM perspective? I am trying to avoid creating another object to handle notifications in another thread, as this will complicate the situation. This API needs to be used in several places, sometimes in a graphical interface, sometimes in a service, etc.

+4
source share
1 answer

My understanding is that the API itself is not limited to stream control, and you intend to receive notifications of background streams through the COM receiver interface.

Three are several ways to solve the problem, while maintaining COM compatibility at the same time. The simplest thing is to change the global apartment model for the application, so that the "main" GUI thread is initialized as an MTA. Although this may work, you can quickly find out that it is incompatible with something else, such as an ActiveX control registered with the Threading "Arartment" model.

, COM, API . MFC, , ( / API). , API .NET, .

COM STA , . API STA, Sink (COM-, MFC STA, , ​​ COM-, ..). API- MTA (CoMarshalInterThreadInterfaceInStream ). API MTA. threda , , , , MFC -. , , MFC ( ..). STA, COM , API .

+2

Source: https://habr.com/ru/post/1502969/


All Articles