在非 Microsoft 平台上使用组件对象模型 (COM)

编程入门 行业动态 更新时间:2024-10-24 20:17:01
本文介绍了在非 Microsoft 平台上使用组件对象模型 (COM)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I'm regularly running into similar situations : I have a bunch of COM .DLLs (no IDL files) which I need to use and invoke to be able to access some foreign (non-open, non-documented) data format.

Microsoft's Visual Studio platform has very nice capabilities to import such COM DLLs and use them in my project (Visual C++'s #import directive, or picking and adding them using Visual Basic .NET's dialogs) - and that's the vendors recommended way to use them.

I would be interested into finding a way to use those DLLs on non-microsoft development platforms. Namely, using these COM classes in C++ project compiled with MinGW or Cygwin, or even Wine's GCC port to linux (compiles C++ targeting Win32 into binary running natively on Linux).

I have got some limited success using this driver, but this isn't successful in 100% of situations (I can't use COM objects returned by some methods).

Has someone had success in similar situations ?

解决方案

Answering myself but I managed to find the perfect library for OLE/COM calling in non-Microsoft compilers : disphelper.

(it's available from sourceforge under a permissive BSD license).

It works both in C and C++ (and thus any other language with C bindings as well). It uses a printf/scanf-like format string syntax. (You pass whatever you want as long as you specify it in the format string, unlike XYDispDriver which requires the arguments to exactly match whatever is specified in the type library).

I modified it a little bit to get it also compile under Linux with WineGCC (to produce native Linux elf out of Win32 code), and to handle "by ref" calls automatically (stock disthelper requires the programmer to setup his/her own VARIANT).

My patched version and patches are available as a fork on github:

  • github/DrYak/disphelper

And here are my patches :

  • patch for single source

  • patch for split source

更多推荐

在非 Microsoft 平台上使用组件对象模型 (COM)

本文发布于:2023-11-05 12:50:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560876.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   模型   对象   平台上   Microsoft

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!