Loading a 32-bit or 64-bit parallel COM DLL, depending on the bit rate at which the application is running

I have a .NET application that uses COM DLLs, of which there are 32-bit and 64-bit versions. I wrote two application manifests that make COM interoperability work on 32-bit or 64-bit operations. Here is the 32-bit version:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
  <assemblyIdentity name="MyApp" version="1.0.0.0" type="win32" />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity 
           type="win32" 
           name="MyCOMDll_32.dll" 
           version="1.2.3.4" 
           processorArchitecture="x86" 
           publicKeyToken="0000000000000000"
           language="*" />
    </dependentAssembly>
  </dependency>
</assembly>

However, saving two manifests leads to a loss of mobility: you need to decide which version to use when installing the application. And the 64-bit application can no longer be run in 32-bit mode.

.NET 32- 64- DLL , ? : <assemblyIdentity processorArchitecture="x86" .../> <assemblyIdentity processorArchitecture="amd64" .../>, .

. , Moritz

+3
1

. , API- . http://support.microsoft.com/kb/830033/en-us ( cookie IntPtr, uint). EnsureActivationContextCreated()


if (!contextCreationSucceeded)
{
    string manifestLoc = Environment.Is64BitProcess
    ? "MyCOMDll_64.dll.manifest"
    : "MyCOMDll_32.dll.manifest";

    myComActivationContext = new NativeMethods.ACTCTX();
    myComActivationContext.cbSize = Marshal.SizeOf(typeof(NativeMethods.ACTCTX));
    myComActivationContext.lpSource = manifestLoc;

    // Note this will fail gracefully if file specified
    // by manifestLoc doesn't exist.
    hActCtx = NativeMethods.CreateActCtx(ref myComActivationContext);
    contextCreationSucceeded = hActCtx != Failed;
}
+1

Source: https://habr.com/ru/post/1756172/


All Articles