简体   繁体   中英

Register 32-Bit COM Class in 64-Bit Component

I have built a ContextMenuHandler for the Windows Explorer shell using SharpShell . The assembly is built for AnyCPU, ie in MSIL, and can therefore run as both 32 bit and 64 bit.

I intend to run this on 64 bit windows only, however, 32 bit applications on windows 64 still use the 32 bit version of the shell for open dialogs, etc.

I have registered this assembly manually using the regasm tool on both architectures (32 & 64) and it works fine in the 64bit windows explorer. It also works from file open, and other shell provided dialogs, in 32 bit applications. This is the intended behavior, great!

The problem I have is writing the installation script, I'm using Wix 3.7 and I don't want to use regasm.

The 64 bit component is installed with:-

<Component Id="cmpMyAssembly64" Directory="INSTALL_TO_HERE"
    Location="local" Win64="yes">
  <File Id="filMyAssembly" KeyPath="yes" Source="mySource.dll"
      Assembly=".net" AssemblyApplication="filMyAssembly"
      ProcessorArchitecture="msil"/>

  <Class Id="01201201-0000-0000-0000-012345670123" Description="My Handler"
         Context="InprocServer32" ThreadingModel="both" ForeignServer="mscoree.dll">
    <ProgId Id="A.ContextHandler" Description="Does something" />
  </Class>

  <RegistryKey Root="HKCR" Key="CLSID\{01201201-0000-0000-0000-012345670123}"
      ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
    <RegistryKey Key="Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}">
      <RegistryValue Value="" Type="string" />
    </RegistryKey>

    <RegistryKey Key="InprocServer32">
      <RegistryKey Key="1.0.0.0">
        <RegistryValue Name="Class" Value="aNamespace.theClass" Type="string" />
        <RegistryValue Name="Assembly" Value="!(bind.assemblyFullName.filMyAssembly)" Type="string" />
        <RegistryValue Name="RuntimeVersion" Value="v4.0.30319" Type="string" />
        <RegistryValue Name="CodeBase" Value="file:///[#filMyAssembly]" Type="string" />
      </RegistryKey>

        <RegistryValue Name="Class" Value="aNamespace.theClass" Type="string" />
        <RegistryValue Name="Assembly" Value="!(bind.assemblyFullName.filMyAssembly)" Type="string" />
        <RegistryValue Name="RuntimeVersion" Value="v4.0.30319" Type="string" />
        <RegistryValue Name="CodeBase" Value="file:///[#filMyAssembly]" Type="string" />
    </RegistryKey>
  </RegistryKey>

  <RegistryValue Root="HKCR" Key="Directory\Background\shellex\ContextMenuHandlers\MyHandler" Value="{guid}" Type="string" Action="write" />
  <RegistryValue Root="HKCR" Key="Directory\shellex\ContextMenuHandlers\MyHandler" Value="{guid}" Type="string" Action="write" />
  <RegistryValue Root="HKCR" Key="Drive\shellex\ContextMenuHandlers\MyHandler" Value="{guid}" Type="string" Action="write" />
</Component>

The problem I have is with the 32bit version's registration. Because it uses the same assembly I don't want to install the same file twice. All I do is create another (32 bit) component and make the necessary registry changes.

<Component Id="cmp32BitVersion" Directory="INSTALL_TO_32"
    Location="local" Win64="no">
  <Class ... just like 64bit
  <RegistryKey ... just like 64bit
</Component>

Now, I assumed that the Win64 yes/no is how windows installer decides which part of the registry to write to. For 64bit components it writes to HKCR..., for the 32 bit component it would write to HKLM\\SOFTWARE\\WOW6432Node\\Classes. The problem I have is that because both components are using a file reference [#filMyAssembly] I am getting ICE69: Mismatched component reference, warnings. The code still builds but I would prefer not to get the warnings, people who don't heed warnings should expect trouble.

Anyway, my question is: what is the correct way to register a MSIL assembly for COM in both 64 and 32 bit applications using Wix/Windows Installer?

MikeR and nickheppleston at wix-users look like they've found a solution:

http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/64-bit-and-32-bit-Registry-Keys-in-same-MSI-td4439679.html

Thanks all who have responded. I followed MikeR's comments and came up with the following - I found that I had to reference the x64 Architecture variable when defining both the Component and the ComponentRef within the Feature section, as follows:

<Component Id="x86LicencingRegistryKeys" Guid="D113AD25-9E80-44E9-80C0-D66828809DBF" Win64="no">


        <RegistryKey Id="x86ValidationCodeRegKey" Root="HKLM" Key="SOFTWARE\Product\Licencing" Action="createAndRemoveOnUninstall">
                <RegistryValue Id="x86ValidationCodeRegValue" Name="ValidationCode" Action="write" Value="BgIAAACkAABSU0ExgAEAAAEAAQD9iAIysvGIxaJcIiENpOVTZbQosafHa9yXlfG0kxSWKJ01Hlfl+I+4ul5LhxoZkLo=" Type="string" />
                <Permission User="Administrators" ChangePermission="yes" GenericAll="yes" />
                <Permission User="CREATOR OWNER" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Power Users" ChangePermission="yes" GenericAll="yes" />
                <Permission User="SYSTEM" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Users" ChangePermission="yes" GenericAll="no" GenericRead="yes" />
        </RegistryKey>



        <RegistryKey Id="x86LicenceKeyRegKey" Root="HKLM" Key="SOFTWARE\Product\Licencing" Action="createAndRemoveOnUninstall">
                <RegistryValue Id="x86LicenceKeyRegValue" Name="LicenceKey" Action="write" Value="" Type="string" />
                <Permission User="Administrators" ChangePermission="yes" GenericAll="yes" />
                <Permission User="CREATOR OWNER" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Power Users" ChangePermission="yes" GenericAll="yes" />
                <Permission User="SYSTEM" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Users" ChangePermission="yes" GenericAll="no" GenericRead="yes" />                               
        </RegistryKey>


</Component>


<?if $(var.Architecture)=x64 ?>

<Component Id="x64LicencingRegistryKeys" Guid="49A15EB4-2DF8-4FF9-83ED-D306F076E232" Win64="yes">


        <RegistryKey Id="x64ValidationCodeRegKey" Root="HKLM" Key="SOFTWARE\Product\Licencing" Action="createAndRemoveOnUninstall">
                <RegistryValue Id="x64ValidationCodeRegValue" Name="ValidationCode" Action="write" Value="BgIAAACkAABSU0ExgAEAAAEAAQD9iAIysvGIxaJcIiENpOVTZbQosafHa9yXlfG0kxSWKJ01Hlfl+I+4ul5LhxoZkLo=" Type="string" />
                <Permission User="Administrators" ChangePermission="yes" GenericAll="yes" />
                <Permission User="CREATOR OWNER" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Power Users" ChangePermission="yes" GenericAll="yes" />
                <Permission User="SYSTEM" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Users" ChangePermission="yes" GenericAll="no" GenericRead="yes" />
        </RegistryKey>



        <RegistryKey Id="x64LicenceKeyRegKey" Root="HKLM" Key="SOFTWARE\Product\Licencing" Action="createAndRemoveOnUninstall">
                <RegistryValue Id="x64LicenceKeyRegValue" Name="LicenceKey" Action="write" Value="" Type="string" />
                <Permission User="Administrators" ChangePermission="yes" GenericAll="yes" />
                <Permission User="CREATOR OWNER" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Power Users" ChangePermission="yes" GenericAll="yes" />
                <Permission User="SYSTEM" ChangePermission="yes" GenericAll="yes" />
                <Permission User="Users" ChangePermission="yes" GenericAll="no" GenericRead="yes" />                               
        </RegistryKey>


</Component>

<?endif ?>


<Feature Id="Complete" Title="TITLE" Description="Complete Package" Display="expand" Level="1" ConfigurableDirectory="INSTALLDIR">
<ComponentRef Id="x86LicencingRegistryKeys" /> 
<?if $(var.Architecture)=x64 ?><ComponentRef Id="x64LicencingRegistryKeys" /><?endif ?> 
</Feature>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM