Working example of a custom DLL Surrogate?

AdamRudolph-4049 5 Reputation points
2023-02-28T16:33:29.9966667+00:00

I have a COM facing 64bit DLL that I can successfully call from a 32Bit process using the built-in DLL Surrogate (dllhost.exe). The main issue with performing execution this way is that the parent process is C:\Windows\System32\dllhost.exe. The codebase location is the Windows\System32 folder. Example of how this accomplished is described in this article.

The DLL I am calling into needs to have its parent process in a specific codebase location for IoC bootstrapping. Further down in processing, references for loading modules through reflection would also need to have the parent process exist in our main codebase folder. From what I can gather, a custom DLL surrogate would allow existing code to execute properly. However, the MS doc which describes creating a custom DLL surrogate only gives hints on how-to write one. Not a working practical example. Is there a working example of a DLL surrogate process available?

Today we are calling into this DLL from a custom 64bit console app launched from a 32bit process. Although this works, the main issue with this is that the bootstrapping process takes time. Being a console app, this spin up happens every time the executable is launched for the job it is designed to do. It and the modules it loads are released when the executable completes. My hope is that a custom DLL surrogate process can be written/exist in our main codebase folder so that the 64bit COM facing DLL can be used in much the same way as the console app executable uses it. In turn, this DLL Surrogate process would call into the 64bit COM facing DLL, bootstrap/spin-up and be persisted for subsequent calls. This way eliminating the time we currently experience for multiple calls into the 64bit side with the console app.

If there is a working example of custom DLL surrogate process available, I would appreciate it.

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,875 questions
0 comments No comments
{count} vote