通过 PInvoke
var assemblies = new NRegFreeCom.AssemblySystem();
var module = assemblies.LoadFrom(Path.Combine(Environment.CurrentDirectory, "AutoItX3.dll"));
var createdDirectly = NRegFreeCom.ActivationContext.CreateInstanceDirectly(module, clsid) as IAutoItX3;
createdDirectly.Run("Notepad");
通过清单
AutoItX3.dll.manifest:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="AutoItX3.dll" version="3.3.8.1" />
<file name = "AutoItX3.dll">
<comClass
clsid="{1A671297-FA74-4422-80FA-6C5D8CE4DE04}"
threadingModel = "Free" />
<typelib tlbid="{F8937E53-D444-4E71-9725-35B64210CC3B}"
version="1.0" helpdir=""/>
</file>
<comInterfaceExternalProxyStub
name="IAutoItX3"
iid="{3D54C6B8-D283-40E0-8FAB-C97F05947EE8}"
proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
baseInterface="{00000000-0000-0000-C000-000000000046}"
tlbid = "{F8937E53-D444-4E71-9275-35B64210CC3B}" />
</assembly>
AutoItX3Dependency.manifest:
<?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">
<dependency>
<dependentAssembly asmv2:codebase="AutoItX3.dll.manifest">
<assemblyIdentity name="AutoItX3.dll" version="3.3.8.1" type="win32" />
</dependentAssembly>
</dependency>
</asmv1:assembly>
Program.cs 主要:
var createdViaManifest = NRegFreeCom.ActivationContext.CreateInstanceWithManifest(new Guid("{1A671297-FA74-4422-80FA-6C5D8CE4DE04}"), "AutoItX3Dependency.manifest");
var autoItWithManifest = (IAutoItX3)createdViaManifest;
autoItWithManifest.Run("Notepad");
代码在 C# ( https://github.com/asd-and-Rizzo/NRegFreeCom )中使用免费注册工具。代码截取自(https://github.com/asd-and-Rizzo/pyautoit)