我想将类型库(tlb)导入到C#中。将TLB导入C#
如何将.tlb
导入.cs
代码文件?
的Borland Delphi能够通过使用命令行工具tlibimp.exe
导入.tlb
到.pas
:
C:\Develop>tlibimp.exe SopQuotingEngineActiveX.tlb
Borland TLIBIMP Version 5.1 Copyright (c) 1997, 2000 Inprise Corporation
Type library loaded...
Created C:\Develop\SopQuotingEngineActiveX_TLB.dcr
Created C:\Develop\SopQuotingEngineActiveX_TLB.pas
现在有含有常量,枚举,即是编译的内部接口.pas
源代码文件类型库(tlb)文件:
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;
什么是.NET C#等同于将类型库导入本机C#代码?
注意:我一直在使用tlbimp.exe
自带的Windows SDK的尝试,但进口类型库进入托管程序集DLL:
C:\Develop>"c:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\x64\tlbimp" 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
什么是.NET C#等价物将类型库导入本机C#代码?
注:我希望看到的是与所有必要的接口,常量,枚举一个.cs
代码文件 - 调用COM对象所需的一切。对于实施例缘故:
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
{
}
(除了没有错误)
参见
- Convert Interface IDL file to C#
- How to read TLB(Type Libraries)of unmanaged code from C# ?
- .NET C#: Is it possible to import TLB (semi-)automatically and add PreserveSig to one type?
- Type Library Importer (Tlbimp.exe)
为什么组装不够?你可以在你的项目中引用它,如果你想看看它包含什么,你可以反思它。为什么你需要C#源代码? – 2011-04-29 15:53:23
@Marius Bancila:单一二进制。 – 2011-04-29 17:03:19
@IanBoyd你最终怎么解决这个问题?我已经看到了下面的答案,但是这让我很不高兴......:'[ – MoonKnight 2014-02-28 15:03:25