Example Analysis of the COM component Initialization Method in C ++
This example describes how to initialize the COM component in C ++. Share it with you for your reference. The details are as follows:
BCB is used here
Initialization is required when using components such as TADOConnect.
Call interface:
?
1 2 |
CoInitialize (NULL); // initialize the COM suite CoUninitialize (); // release the COM suite |
Call in the DLL entry:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Static bool isCoInitialize = false; // whether it is self-initiated Int WINAPI DllEntryPoint (HINSTANCE hinst, unsigned long reason, void * lpReserved) { If (reason = DLL_PROCESS_ATTACH) { If (ConInitialize (NULL) = S_ OK) isCoInitialize = true; } If (reason = DLL_PROCESS_DETACH) { If (isCoInitialize) CoUninitialize (); // It is released only when it is initialized. Otherwise, it is released by other initialization places, // Prevent other callers from failing due to wrong release } Return 1; } |
I hope this article will help you with C ++ programming.