Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Volume I, Issue 7
Any COM component that is currently being used out-of-process should not present a
problem when you are migrating to 64-bit Windows, because Remote Procedure Calls
(RPCs) can cross 32-bit and 64-bit boundaries without any problems.
In contrast, any application that you have ported to 64-bit and that needs to load a
COM component in-process must implement one of these solutions to continue
using the COM component:
To convert your project from in-process to out-of-process, we’ll also make the following
assumptions:
1. The library currently compiles with Microsoft Visual Studio® 2005.
2. The project is of type ATL (Active Template Library code).
3. Move all of the functionality from the in-process library to your new
project. This step involves moving all the source code and header files
contained in your project.
Note While this is not a hard step, it might be tedious, depending on the
size of your project.
An advantage of this approach is that it is not necessary to perform any changes on the
64-bit client code, only on the 32-bit server project.
One significant benefit of using this approach is that there is no need to change the source
code of either the client or the COM component.
64-bit Insider Newsletter
Volume 1, Issue 7
Page 4/8
Using dllhost as a Surrogate Host
Another way to call a COM library across a 32/64-bit boundary is to use dllhost.exe, (part
of the Windows operating system) as a surrogate host. When you use dllhost, it runs as a
separate process and provides all the mechanisms for the server to run as a local server.
Dllhost works as a wrapper that relays calls between the 32-bit client and the 64-bit DLL.
Windows handles both the activation and the termination of the surrogate process as
needed. Also, the overhead associated with COM+ can be avoided.
COM automatically handles marshaling, and the client code gets a proxy and a stub
instead of directly addressing the DLL as it normally would have. The downside to this
approach is that the client code needs to be changed and, when you look in Task
Manager, all you can see is dllhost.exe. If another object is being hosted by dllhost.exe,
you don’t have a quick and practical way of determining which process contains your
object (unless you download a third-party utility, such as Process Explorer by
SystemInternals).
Hosting a COM library in dllhost is not a very complicated procedure. You only need to
complete some changes in the registry on the activation information to specify that the
COM library will run as a surrogate and change the way the client loads the COM object.
1. Change the AppId value of the library’s Global Unique Identifier (GUID)
contained in the HKEY_CLASSES_ROOT\CLSID\{YOUR-CLSID} node, so
that the AppId contains its own GUID as the corresponding value. In this
example, we have a COM object with a name of CConversion (See Figure 3).
These are the only two changes that you must make for the COM library. The binary
stays the same. As far as the changes required in the client application, we only need to
change the activation information. To create an in-process (commonly called “in-proc”)
COM instance from C++, it is necessary to call the CoCreateInstance function with only
one parameter, the GUID of the class to be instanced. However, to create an out-of-
process (or “out-of proc”), it is necessary to pass as a parameter
CLSCTX_LOCAL_SERVER.
The following code shows how you could create an out-of-proc COM instance.
HRESULT hr = spUnknown.CoCreateInstance(__uuidof(CConversion), NULL, LSCTX_LOCAL_SERVER);
By performing these simple changes, the COM library will run as a surrogate, and the
application will be able to access the functionality with just one minor change and a
recompile.
In this example, we’ll also assume that we cannot migrate the basic math library, but can
migrate the rest of the application. Consequently, we have to find a way to use a Win32
library out-of-process. A good way to solve this challenge is to build an out-of-process
COM wrapper (See Figure 5).
This way, the 64-bit application will be able to call the 32-bit COM wrapper that is
running in a separate process space. The COM wrapper will then forward these calls to
the 32-bit DLL and return the results of these calls to the 64-bit process.
Wrapping the DLL in an out-of-proc COM Component will involve changing the
references in the 64-bit client application and modifying it so that it calls the new COM
wrapper. There will be no changes to the 32-bit DLL.
Summary
During the process of upgrading an application to Windows 64-bit, there’s a possibility
that not all references might be available natively. On a first impression, this might look
like a showstopper; however, there is a way to continue using your references by moving
them out-of-process.
Any methodology that you decide to use will allow you to interoperate and continue
using your 32-bit libraries from 64-bit applications.
Additional Reading
Overview of Compatibility Considerations for 32-bit and 64-bit
http://support.microsoft.com/kb/896456/en-us