ADO in a DLL
-
Hey, I wanted to know that whether it is safe to use ADO in a DLL? The reason I'm asking this is that, to use ADO we need to initialize COM right? So calling CoInitialize in a DLL, is it okay?
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
-
Hey, I wanted to know that whether it is safe to use ADO in a DLL? The reason I'm asking this is that, to use ADO we need to initialize COM right? So calling CoInitialize in a DLL, is it okay?
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
Ahmed Manzoor wrote:
we need to initialize COM right? So calling CoInitialize in a DLL, is it okay?
Yes. You do it and the matching uninitialize in DLLMain for every Process and Thread attach/detach message. From the documentation: Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or CoUninitialize from the DllMain function. link[^]
-
Ahmed Manzoor wrote:
we need to initialize COM right? So calling CoInitialize in a DLL, is it okay?
Yes. You do it and the matching uninitialize in DLLMain for every Process and Thread attach/detach message. From the documentation: Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or CoUninitialize from the DllMain function. link[^]
-
What do you mean? Is it safe? Will there be any malfunction?
Top Web Hosting Providers[^] Do, or do not. There is no 'try'.
Ahmed Manzoor wrote:
Will there be any malfunction?
That depends on you, your analysis of your scenario and developing a correct solution. Make sure you read the documentation I provided a link to. The best scenario is the host process has already handled COM initialization. If that isn't happening then you have a less than perfect scenario. Make sure you understand the ramifications and develop the proper error handling code for the potential scenarios that could occur based on your hosting scenario. My fault, I should have mentioned that your scenario can also call for dealing with the initialization in other exports of your DLL rather than DLLMain. The problem with that is you need to account for the messages you get passed in DLLMain so that you know which event is happening. It's really up to you to figure all this out based on your project details.
-
Ahmed Manzoor wrote:
Will there be any malfunction?
That depends on you, your analysis of your scenario and developing a correct solution. Make sure you read the documentation I provided a link to. The best scenario is the host process has already handled COM initialization. If that isn't happening then you have a less than perfect scenario. Make sure you understand the ramifications and develop the proper error handling code for the potential scenarios that could occur based on your hosting scenario. My fault, I should have mentioned that your scenario can also call for dealing with the initialization in other exports of your DLL rather than DLLMain. The problem with that is you need to account for the messages you get passed in DLLMain so that you know which event is happening. It's really up to you to figure all this out based on your project details.