Calling CoCreateInstance CLSCTX_INPROC_SERVER from a 32 bits app, but the COM server .dll is x64

Pablo Glomby 186 Reputation points
2022-04-22T18:21:04.77+00:00

Hi!
I have a question... I call CoCreateInstance with CLSCTX_INPROC_SERVER from an x86 app but the registered .dll is a 64 bits library.
Is there a way to instantiate it by doing a trick? I mean... I see for example there is an undocumented SHCreateLocalServerRundll API that may be run using rundll32.exe but it's not documented...

Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 40,286 Reputation points
    2022-04-22T19:19:17.773+00:00

    You can instantiate a 64-bit com server from a 32-bit client if the server is an out-of-process server. A COM server hosted in a 64-bit DLL can be instantiated as an out-of-process server by using the system COM surrogate.

    https://learn.microsoft.com/en-us/windows/win32/com/dllsurrogate
    https://learn.microsoft.com/en-us/windows/win32/com/registering-the-dll-server-for-surrogate-activation

    Example usage update -
    The screenshot below shows a COM server hosted in a 64-bit DLL being instantiated by a 64-bit client directly and as an out-of-process server using the system's COM Surrogate.

    It also shows a 32-bit client failing when attempting to instantiate it as an in-process server but succeeding when using the COM surrogate to instantiate the 64-bit server as out-of-process.

    195787-surrogate.png

    1 person found this answer helpful.
    0 comments No comments