简体   繁体   中英

instancing com object allowed in dllmain() / DLL_PROCESS_ATTACH?

Loading DLLs in in DLLMAIN() / DLL_PROCESS_ATTACH may cause trouble. But may COM Objects be instanced using eq CoInitialize() / CoCreateInstance()?

EDIT : The question is: Could creating COM instances cause similar errors like loading DLLs in this circumstances? Loading DLLs an creating COM instances seem to me similar in a way.

I'm not sure where you got that quote from, but it doesn't sound right.

You should never put any code of any significance into DllMain. Especially code that invokes LoadLibrary. Many Windows APIs will call LoadLibrary under the hood, so it's best to avoid doing any complex initialization here. Use a global C++ object (for it's constructor) or better yet, export a function for initialization.

CoCreateInstance for in-proc components ultimately will call LoadLibrary or one of its variants. It would not be wise to call this function in DllMain either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM