com interop - Loading a 32-bit or 64-bit side-by-side COM DLL depending on the bitness with which the application runs -


i have .net application uses com dll, of there both 32bit , 64bit version. have written 2 application manifests make side-by-side com interop work on either 32 bit or 64 bit. here 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, maintaining 2 manifests leads loss of portability: need decide version use when install application. , 64-bit application can no longer run in 32-bit mode.

is there possibility .net application load correct 32-bit or 64-bit dll depending on bitness under runs? have tried using 2 dependency elements, 1 <assemblyidentity processorarchitecture="x86" .../> , 1 <assemblyidentity processorarchitecture="amd64" .../>, results in application configuration error.

i'd grateful answers. regards, moritz

i have not found way application manifest.therefore, dropped application manifest in favor of programmatic solution using activation context api. solution has been adapted http://support.microsoft.com/kb/830033/en-us (where field cookie must intptr not uint). have replaced inner part of ensureactivationcontextcreated() method by

 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 fail gracefully if file specified     // manifestloc doesn't exist.     hactctx = nativemethods.createactctx(ref mycomactivationcontext);     contextcreationsucceeded = hactctx != failed; } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -