<bdo id='bA1wz'></bdo><ul id='bA1wz'></ul>
<tfoot id='bA1wz'></tfoot>
  • <legend id='bA1wz'><style id='bA1wz'><dir id='bA1wz'><q id='bA1wz'></q></dir></style></legend>
  • <i id='bA1wz'><tr id='bA1wz'><dt id='bA1wz'><q id='bA1wz'><span id='bA1wz'><b id='bA1wz'><form id='bA1wz'><ins id='bA1wz'></ins><ul id='bA1wz'></ul><sub id='bA1wz'></sub></form><legend id='bA1wz'></legend><bdo id='bA1wz'><pre id='bA1wz'><center id='bA1wz'></center></pre></bdo></b><th id='bA1wz'></th></span></q></dt></tr></i><div id='bA1wz'><tfoot id='bA1wz'></tfoot><dl id='bA1wz'><fieldset id='bA1wz'></fieldset></dl></div>

      1. <small id='bA1wz'></small><noframes id='bA1wz'>

        将 TLB 导入 C#

        Import TLB into C#(将 TLB 导入 C#)
        <tfoot id='e2De9'></tfoot>
        • <bdo id='e2De9'></bdo><ul id='e2De9'></ul>
          • <i id='e2De9'><tr id='e2De9'><dt id='e2De9'><q id='e2De9'><span id='e2De9'><b id='e2De9'><form id='e2De9'><ins id='e2De9'></ins><ul id='e2De9'></ul><sub id='e2De9'></sub></form><legend id='e2De9'></legend><bdo id='e2De9'><pre id='e2De9'><center id='e2De9'></center></pre></bdo></b><th id='e2De9'></th></span></q></dt></tr></i><div id='e2De9'><tfoot id='e2De9'></tfoot><dl id='e2De9'><fieldset id='e2De9'></fieldset></dl></div>

            <small id='e2De9'></small><noframes id='e2De9'>

              <legend id='e2De9'><style id='e2De9'><dir id='e2De9'><q id='e2De9'></q></dir></style></legend>

                <tbody id='e2De9'></tbody>

                • 本文介绍了将 TLB 导入 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想将类型库 (tlb) 导入 C#.

                  i want to import a Type Library (tlb) into C#.

                  如何将 .tlb 导入 .cs 代码文件?

                  How do i import a .tlb into a .cs code file?

                  Borland Delphi 可以使用命令行工具tlibimp.exe.tlb 导入.pas:

                  Borland Delphi can import a .tlb into .pas by using the command line tool tlibimp.exe:

                  C:Develop>tlibimp.exe SopQuotingEngineActiveX.tlb
                  Borland TLIBIMP Version 5.1  Copyright (c) 1997, 2000 Inprise Corporation
                  Type library loaded...
                  Created C:DevelopSopQuotingEngineActiveX_TLB.dcr
                  Created C:DevelopSopQuotingEngineActiveX_TLB.pas
                  

                  现在有一个 .pas 源代码文件,其中包含已编译的类型库 (tlb) 文件中的常量、枚举、接口:

                  And now there is a .pas source code file containing constants, enumerations, interfaces that were inside the compiled Type Library (tlb) file:

                  SopQuotingEngineActiveX_TLB.pas:

                  unit SopQuotingEngineActiveX_TLB;
                  
                  interface
                  ...
                  const
                     CLASS_XSopQuotingEngine: TGUID = '{3A46FFB8-8092-4920-AEE4-0A1AAACF81A0}';
                  ...
                  
                  // *********************************************************************//
                  // Interface: IXSopQuotingEngine
                  // Flags:     (4416) Dual OleAutomation Dispatchable
                  // GUID:      {AA3B73CC-8ED6-4261-AB68-E6AE154D7D52}
                  // *********************************************************************//
                    IXSopQuotingEngine = interface(IDispatch)
                      ['{AA3B73CC-8ED6-4261-AB68-E6AE154D7D52}']
                      procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
                      procedure OnEndPage; safecall;
                      procedure Connect(const ConnectionString: WideString); safecall;
                      procedure Disconnect; safecall;
                      function  xmlRateQuote(const xmlQuote: WideString): WideString; safecall;
                    end;
                    ...
                  
                    CoXSopQuotingEngine = class
                      class function Create: IXSopQuotingEngine;
                    end;
                  

                  将类型库导入本机 C# 代码的 .NET C# 等效项是什么?

                  What is the .NET C# equivalent for importing a type library into native C# code?

                  注意:我曾尝试使用 Windows SDK 附带的 tlbimp.exe,但会将类型库导入托管程序集 dll:

                  Note: i have tried using tlbimp.exe that comes with the Windows SDK, but that imports a type library into a managed assembly dll:

                  C:Develop>"c:Program FilesMicrosoft SDKsWindowsv7.1BinNETFX 4.0 Toolsx64	lbimp" SopQuotingEngineActiveX.tlb
                  Microsoft (R) .NET Framework Type Library to Assembly Converter 4.0.30319.1
                  Copyright (C) Microsoft Corporation.  All rights reserved.
                  
                  TlbImp : warning TI3002 : Importing a type library into a platform agnostic assembly.  This can cause errors if the type library is not truly platform agnostic.
                  TlbImp : Type library imported to SopQuotingEngineActiveX.dll
                  

                  将类型库导入本机 C# 代码的 .NET C# 等效项是什么?

                  What is the .NET C# equivalent for importing a type library into native C# code?

                  注意:我想看到的是一个 .cs 代码文件,其中包含所有必需的接口、常量、枚举——调用 COM 对象所需的一切.例如:

                  Note: What i want to see is a .cs code file with all the required interfaces, constants, enumerations - everything required to call the COM object. For examples sake:

                  SopQuotingEngineActiveX.cs

                  [ComImport, Guid("AA3B73CC-8ED6-4261-AB68-E6AE154D7D52")
                         ]
                  public interface IXSopQuotingEngine
                  {
                      void OnStartPage(object AScriptingContext);
                      void OnEndPage();
                      void Connect(string ConnectionString);
                      void Disconnect();
                      string xmlRateQuote(string xmlQuote);
                  }
                  
                  [ComImport, Guid("3A46FFB8-8092-4920-AEE4-0A1AAACF81A0")]
                  public class XSopQuotingEngineClass
                  {
                  }
                  

                  (除了没有错误)

                  • 将接口 IDL 文件转换为 C#
                  • 如何读取非托管代码的TLB(类型库)来自 C#?
                  • .NET C#:是否可以(半)自动导入 TLB 并将 PreserveSig 添加到一种类型?
                  • 类型库导入器 (Tlbimp.exe)

                  推荐答案

                  您已经找到了 .Net 等价物 Tlbimp.exe - 这个输出是一个程序集,不幸的是没有办法改变它.

                  You've already found the .Net equivalent, Tlbimp.exe - The output from this is an assembly and unfortunately there is no way to change this.

                  如果您想查看接口等的 C# 声明......那么您应该使用反编译器(例如 Reflector 或 ILSpy) 在生成的程序集中.此外,微软关于如何修改这些声明的官方建议是修改生成的 MSIL - 请参阅 自定义主要互操作程序集.

                  If you want to see C# declarations of interfaces etc... then you should use a decompiler (such as Reflector or ILSpy) on the resulting assembly. Also the official advice from Microsoft on how to modify these declarations is to modify the resulting MSIL - see Customizing Primary Interop Assemblies .

                  (目前)唯一的替代方法是自己手工制作所有声明.

                  The only alternative to this (currently) is to hand craft all the declarations yourself.

                  这篇关于将 TLB 导入 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)

                    <small id='tK0tj'></small><noframes id='tK0tj'>

                    • <legend id='tK0tj'><style id='tK0tj'><dir id='tK0tj'><q id='tK0tj'></q></dir></style></legend>
                        <tfoot id='tK0tj'></tfoot>
                        <i id='tK0tj'><tr id='tK0tj'><dt id='tK0tj'><q id='tK0tj'><span id='tK0tj'><b id='tK0tj'><form id='tK0tj'><ins id='tK0tj'></ins><ul id='tK0tj'></ul><sub id='tK0tj'></sub></form><legend id='tK0tj'></legend><bdo id='tK0tj'><pre id='tK0tj'><center id='tK0tj'></center></pre></bdo></b><th id='tK0tj'></th></span></q></dt></tr></i><div id='tK0tj'><tfoot id='tK0tj'></tfoot><dl id='tK0tj'><fieldset id='tK0tj'></fieldset></dl></div>
                          <tbody id='tK0tj'></tbody>
                        • <bdo id='tK0tj'></bdo><ul id='tK0tj'></ul>