com - Import TLB into C# -


i want import type library (tlb) c#.

how import .tlb .cs code file?


borland delphi can import .tlb .pas using 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:\develop\sopquotingengineactivex_tlb.dcr created c:\develop\sopquotingengineactivex_tlb.pas 

and there .pas source code file containing constants, enumerations, interfaces inside 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; 

what .net c# equivalent importing type library native c# code?


note: have tried using tlbimp.exe comes windows sdk, imports type library managed assembly 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 assembly converter 4.0.30319.1 copyright (c) microsoft corporation.  rights reserved.  tlbimp : warning ti3002 : importing type library platform agnostic assembly.  can cause errors if type library not platform agnostic. tlbimp : type library imported sopquotingengineactivex.dll 

what .net c# equivalent importing type library native c# code?


note: want see .cs code file required interfaces, constants, enumerations - required call com object. 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 { } 

(except without bugs)

see also

you've found .net equivalent, tlbimp.exe - output assembly , unfortunately there no way change this.

if want see c# declarations of interfaces etc... should use decompiler (such reflector or ilspy) on resulting assembly. official advice microsoft on how modify these declarations modify resulting msil - see customizing primary interop assemblies .

the alternative (currently) hand craft declarations yourself.


Comments