The SetDllHost Tool


COM objects are shipped in a variety of different formats. Examples include dynamic link libraries (.dll), ActiveX Controls (.ocx), executables (.exe) and Windows NT/Windows 2000 services.

When these objects are accessed via DCOM from a remote machine, the operating system must load them into memory. Executables and services are easy as they can be run or started by the operating system. Dynamic Link Libraries are different however, they need to be loaded into a running process as they cannot run by themselves.

The DCOM infrastructure on Windows has a facility to handle this case and it is called surrogacy. Basically you configure the registry to indicate the name of a surrogate program which will load the dll for you, on demand. Microsoft have supplied such a surrogate program which can host almost all COM objects that have been implemented as dlls. It is called dllhost.exe.

Because OCX components must be loaded in-process, you also need to configure the surrogacy if your Java client accesses an OCX component without embedding it in a Java GUI.

Command Line Options

Running setdllhost /? we get the following output:


C:\>setdllhost /?

setdllhost version Intrinsyc Software International, Inc.

Usage: setdllhost <DLL> [<DLL> ...] "description"
<DLL>: Path and name of a DLL

Usage: setdllhost @<listFile> "description"
listFile: Text file where each line contains the path and name of a DLL

Usage: setdllhost [/list | /unregister <surrogate>]
  /list: Lists all surrogates
  /unregister <surrogate>: Unregisters the specified surrogate

Remote Access

DCOM is used if your Java client and the COM component are on different machine. After using the Setdllhost, the surrogate can be listed in the Applications tab of DCOMCNFG and identified by its description name. You can then configure the DCOM settings of the DLL according to Configuring DCOM for Remote Access.

Local Access

If your Java client and the COM component are on the same Windows machine, you have an option to use J-Integra®'s native mode, which has better performance than DCOM mode. DCOM configuration is not typically required in native mode since DCOM communication is not involved. However, if you get access denied errors in native mode, please configure DCOM as in Configuring DCOM for Remote Access.


To setup a surrogate for the DLL AppleTest.dll...

To setup a surrogate for the DLL(s) listed in the file MyDlls.txt...

To list all current surrogates...

To unregister the surrogate named "Apple Test"...

For more information on what setdllhost does to the Windows registry, see Registry Entries Created by Setdllhost in the Knowledge Base.