Example analysis of COM component initialization method in C++
- 2020-04-02 03:02:56
- OfStack
This article illustrates the method of COM component initialization in C++. Share with you for your reference. The details are as follows:
BCB is used here
Initialization is required when using components such as TADOConnect
Calling interface:
CoInitialize(NULL);//Initialize the COM suite
CoUninitialize();// The release of COM suite
Call in DLL entry:
static bool isCoInitialize = false; //Is it your own initialization
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();
//If it is initialized by itself, it will be released. Otherwise, it will be released by other initializers.
//Prevents an error release from causing another caller to fail
}
return 1;
}
Hope that the article described in the C++ programming to help you.