What is the appropriate place to call CoInitialize / CoUninitialize through a DLL?

I am implementing a DLL containing a shared ADO connection using a property ConnectionObject TADOConnectionand passing it across the boundaries of the DLL to other instances TADOConnection. I need to make sure that COM is initialized, so I need to call CoInitialize/ CoUninitialize. This is currently in the context of the main VCL thread, but may be in another place in another thread, which, of course, requires its own instance of COM . I do not do multithreading.

Where is the right place to call them; inside a DLL (during loading / unloading), outside a DLL (calling process), or both? Given this is only one thread, should it not be only once outside of the DLL in the original process?

I assume that the original calling thread should be fully responsible for this, since COM works in the context of the thread. Of course, calling them on both sides should not hurt, but it will also create several instances of COM.

A short story ... In this case, is it safe to be safe? Or is it important to keep only one instance of COM?

+1
source share
1 answer

You should not do this in a DLL. Make it part of the contract between the DLL and the host for which the host is responsible for initializing COM.

, DLL COM, , , . . , COM , , .

, COM DLL. .

+6

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


All Articles