天天看点

Registration-Free Activation of COM

详细介绍一下localloading,也就是 registration-free COM, 包括 C++和 CSharp两种情况下如何使用 

注:clsid, tlbid等 可以使用工具 regsvr42获得 http://www.codeproject.com/Articles/28682/regsvr42-Generate-SxS-Manifest-Files-from-Native-D?fid=1525497&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Normal&spc=Relaxed&fr=26#xx0xx



C++客户端:

client.exe.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity
  type="win32"
  name="client"
  version="1.0.0.0" />
  <dependency>
          <dependentAssembly>
              <assemblyIdentity
                  type="win32"
                  name="sidebyside.X"
                  version="1.0.0.0" />
          </dependentAssembly>
  </dependency>
</assembly>
           

SideBySide.X.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity
	type="win32"
	name="SideBySide.X"
	version="1.0.0.0" />

<file name = "SideBySide.dll">

<comClass
    clsid="{4B72FC46-C543-4101-80DB-7777848D1357}"
    threadingModel = "Apartment" />

<typelib tlbid="{E6A9CD40-8559-4e17-A0D9-C68B038B4FA0}"
       version="1.0" helpdir=""/>

</file>

<comInterfaceExternalProxyStub 
    name="ISideBySideClass" 
    iid="{CBA85B94-9C11-43aa-84F6-30B90145FD3E}"
    proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
    baseInter
    tlbid = "{E6A9CD40-8559-4E17-A0D9-C68B038B4FA0}" />

</assembly>
           
Registration-Free Activation of COM

C#客户端:

Registration-Free Activation of COM
Registration-Free Activation of COM

在manifest结尾处 添加com的引用

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <!-- UAC Manifest Options
            If you want to change the Windows User Account Control level replace the 
            requestedExecutionLevel node with one of the following.

        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />

            Specifying requestedExecutionLevel node will disable file and registry virtualization.
            If you want to utilize File and Registry Virtualization for backward 
            compatibility then delete the requestedExecutionLevel node.
        -->
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
  
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->

      <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
      
    </application>
  </compatibility>
  
  <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
  <!-- <dependency>
    <dependentAssembly>
      <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0"
          processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*"
        />
    </dependentAssembly>
  </dependency>-->

  <file name="sub\sub2\SideBySide.dll">
    <comClass clsid="{4B72FC46-C543-4101-80DB-7777848D1357}" threadingModel="Apartment"></comClass>
    <typelib tlbid="{E6A9CD40-8559-4e17-A0D9-C68B038B4FA0}" version="1.0" helpdir=""></typelib>
  </file>

  <file name="sub\sub2\Component2.dll">
    <comClass clsid="{C0A82024-A279-40AB-8CFF-4E3688458156}" threadingModel="Apartment"></comClass>
    <typelib tlbid="{F1CD9552-9003-40F5-BA1E-6920047BC333}" version="1.0" helpdir=""></typelib>
  </file>

</asmv1:assembly>