views:

227

answers:

2

The description of CoLoadLibrary() says it does pretty much the same as LoadLibraryEx() - loads a DLL into the process. COM classes creation functions - CoCreateInstance() and CoGetClassObject() - both do load the necessary DLL into the process too.

Then why is CoLoadLibrary() needed in the first place and how should it be used?

+3  A: 

Have a look at the code:

mov     edi,edi
push    ebp
mov     ebp,esp
push    8
push    0
push    dword ptr [ebp+8]
call    dword ptr [ole32!_imp__LoadLibraryExW (71eb1214)]
pop     ebp
ret     8

So it just calls:

LoadLibraryEx( FileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ).

Presumably, the routine merely exists for backwards compatibility -- it probably has its roots in Win16.

Johannes Passing
Are there any scenarios when I would need to call it?
sharptooth
None that I can think of -- the functionality CoLoadLibrary once implemented seems to have been removed, so this routine really is just compatibilty baggage.
Johannes Passing
+1  A: 

Perhaps if you were writing your own regsvr32.exe? But JP's disassembly doesn't really support my guess, because you could just use LoadLibraryEx instead. Maybe in the olden days, Microsoft planned on COM DLLs someday being loaded in a different way than regular DLLs (D-COM?), so this was a way of ensuring future compatibility.

Marc Bernier

related questions