如何在纯 C 中使用 IDispatch 调用 COM 对象
我需要使用 R 工具(R Windows 统计程序)中包含的 gcc 编译器来编译我的一些代码,问题是我需要在代码中使用 IDispatch 来创建访问 COM 对象的方法,并且gcc 编译器不支持我用来执行此操作的大部分代码,这些代码基本上是 C++ 代码。
所以我的问题是如何在 C 中使用 IDispatch 创建 COM 对象,而不必依赖 MFC、.NET、C#、WTL 或 ATL。 我相信如果我这样做,我将能够毫无问题地编译我的代码。
I need to compile some code of mine using the gcc compiler included in the R tools (R the statistical program for windows), the problem is that I need to use IDispatch in my code to create an access the methods of a COM object, and the gcc compiler doesn't support much of the code that I'm using to do so, which is basically C++ code.
So my question is how can I use IDispatch in C to create the COM object without having to depend on MFC, .NET, C#, WTL, or ATL. I believe that if I do so I will be able to compile my code without any problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CodeProject 上有一篇很棒的文章,题为“COM in plain C”。
以下是第 1 部分的链接。
在那篇文章和作者的后续文章中,有很多关于在 C 中使用 COM 的非常好的信息(我认为该系列中有 3 或 4 篇文章)。
编辑:
我错了,有8部分!
第 2 部分
第 3 部分
第 4 部分
第 5 部分
第 6 部分
第 7 部分
第 8 部分
There is a great article on CodeProject entitled "COM in plain C".
Here is the link to Part 1.
There is a lot of very good info on working with COM in C in that article and the author's subsequent follow-ups (I think there are 3 or 4 in the series).
Edit:
I was wrong, there are 8 parts!
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7
Part 8
一般来说,C++ IDispatch 接口只是一个函数指针表。
在 C 中,它看起来像这样:
请注意,每个方法都有一个 THIS 指针作为第一个参数,并且您将需要定义更多类型,例如 ITypeInfo、REFIID、DISPID 等。
所以,这是一项艰巨的任务。 但可以用纯 C 创建 C++ 接口。
In general, a C++ IDispatch interface is just a table of function pointers.
In C, it would look something like:
Note that every method has a THIS pointer as the first parameter, and that you will need to define more types, such as ITypeInfo, REFIID, DISPID, etc, etc.
So, its a big task. But it is possible to create C++ interfaces in pure C.
您也可以使用 disphelper 库。
Also you can use disphelper library.