如何使用用C TLB文件? [英] How to use tlb file in C?

查看:181
本文介绍了如何使用用C TLB文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLB文件(使用regasm)从DLL(使用C#code)条作出的,我可以在C使用++使用#import。和一切工作正常。
有没有一种方法,我可以在C语言中使用它?我刚刚发现的#import是C ++特有的。因此,有人可以告诉我,我怎么能在我的C程序中使用?

tlb file(using regasm) is made from a dll(using c# code), and i can use this in c++ using #import. and everything is working fine. Is there a way, i can use this in C language? I just found that #import is c++ specific. So, can someone please tell me how can i use in my C program?

我的主要意图是使用C#开发COM DLL在我的C程序。

my main intention is to use COM DLL developed in C# in my C program.

感谢和放大器; RGDS,
〜卡尔文

Thanks & Rgds, ~calvin

推荐答案

用C COM编程是的非常的痛苦,但并非不可能。降压虽然这里停止。类型库的一点是要有一个工具自动生成COM接口和合作类声明,使您可以在code使用它们。神似.h文件,但语言无关。在.NET相当于是在装配中的元数据。

COM programming in C is very painful, but not impossible. The buck stops here though. The point of a type library is to have a tool auto-generate the COM interface and co-class declarations so that you can use them in your code. Quite similar to a .h file, but language independent. The .NET equivalent is the metadata in an assembly.

问题是,该工具不提供给一个的.tlb转换为C声明。我敢肯定你熟悉的#import,那就是获取MSVC使用。但它生成C ++ code,智能指针,帮助您创建COM对象,调用其接口的方法和处理错误。如果有可用的工具,可生成C,那么这是一个很好的隐藏的秘密。

Problem is, the tooling isn't available to convert a .tlb to C declarations. I'm sure you are familiar with #import, that's what gets used in MSVC. But it generates C++ code, smart pointers that help you create the COM object, call its interface methods and deal with errors. If there is a tool available that generates C then it is a very well hidden secret.

一招跳到主意,你可以使用OLEView.exe这类,文件+查看类型库浏览的类型库的内容。这种观点是反编译成IDL,接口定义语言。您可以复制这个文本粘贴到一个.idl文件,并使用/头命令行选项MIDL.EXE编译。这将生成一个包含C ++和各接口的C声明.h文件。应该让你很近,只需确保该类型库是相当稳定的,所以你不必经常这样做。

One trick jumps to mind, you can use OleView.exe, File + View TypeLib to view the contents of the type library. This view is decompiled into IDL, the interface definition language. You can copy and paste this text into an .idl file and compile it with midl.exe with the /header command line option. This generates a .h file that contains both C++ and the C declarations for the interfaces. Ought to get you close, just make sure that the type library is reasonably stable so you don't have to do this very often.

这篇关于如何使用用C TLB文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆