Have abit of an odd question; I'm using a tool supplied by a large company that, for reasons I find somewhat baffling, uses a COM interface defined inside the exe itself. In the example code they provide, it looks alittle like this.
Compilation error:
MAlonzo/Code/Agda/Primitive.hs:4:18:
Could not find module ‘Data.FFI’
Use -v to see a list of the files searched for.
MAlonzo/Code/Agda/Primitive.hs:5:18:
Could not find module ‘IO.FFI’
Use -v to see a list of the files searched for.
From what I understand, this is the way Microsoft Visual C++ compiler understands the COM and works with it, and I have had the example code working before (currently, it doesn't compile due to fiddling with my build environment).
My question is, is there a way to do the same with MinGW? The project I'm working on is mainly using that; we can use MSVC if required, but I'd ideally like to avoid using multiple compilers if possible. I'm currently using cmake to build with, but I'm willing to use a script to build the items that need the COM interface if needed.
Thanks for your time.
答案 0 :(得分:1)
COM子系统是Windows API的一部分,您可以使用对该API的C调用来访问它。
然而,这涉及到大量的样板。支持COM"开箱即用的编译器"编写了所有这些样板文件,并将其打包成编译库,模板标题等的一些组合。
这些编译器提供的常用工具套件的另一部分是可以从现有编译对象中读取COM接口定义的工具。出于这个原因,COM对象通常包含其接口的二进制表示。
有几种方法可以在这里继续使用g ++;一个选项是遵循这个大纲:
如果你想用g ++编写对象,那么还有很多工作要做,因为你需要实现一堆东西,但这是可能的。
我过去用g ++成功完成了这项工作(作为测试我开发的COM对象的一部分)。可能有人可以开发一个很好的开源套件来使用COM对象,甚至用于创作,这不依赖于MSVC,但我不知道这样的事情。
我建议您阅读Don Box的书籍,如果您只是通过使用它并阅读互联网来了解COM,那么他们会理解您将会遇到很多空白。
答案 1 :(得分:0)
“有没有办法对MinGW做同样的事情”的答案是否定的。 #import是一个可选工具,它读取COM type library(嵌入在二进制文件中或不嵌入,TLB通常对应于.idl文件,但也是可选的),并生成C / C ++代码严重依赖于只有Visual Studio提供的.c和.h文件。
“我可以与MinGW合作”的答案当然是肯定的。我对MinGW和工具了解不多,但你可以用任何编译器做COM,因为COM(只是)binary standard。
如果你摆脱#import,你将不得不改变使用生成的代码(在#import指令的.TLH文件中),COM帮助器,包装器等的代码。它可以是很多工作,但这在技术上是可行的。
现在,在您的上下文中,我认为这实际上取决于.exe的类型库(COM类,接口等的描述)有多大。 Visual Studio的#import增加了价值,因此您必须评估它为您添加的价值。
如果它只是一个类,例如一个接口,那么摆脱#import会很有趣。如果.exe已经有与tlb对应的.h文件,那么你可以使用它们,否则你必须自己重新声明一些(并再次更改使用生成的包装器的代码)。
你问这个问题的唯一事实让我想知道你是否有足够的COM知识(没有冒犯:-)来摆脱Visual Studio。