Search code examples
windowscominteropcom-interop

When and why use CoLoadLibrary?


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?


Solution

  • 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.