我经常遇到类似的情况:我有一堆COM .DLL(没有IDL文件),我需要使用和调用能够访问一些外部(非开放,文档)数据格式。
Microsoft的Visual Studio平台有非常好的功能来导入这样的COM DLL,并在我的项目中使用它们(Visual C ++的#import指令,他们使用Visual Basic .NET的对话框) - 这是供应商推荐的方式使用它们。
我会感兴趣的是找到一种方法来使用这些DLL非microsoft开发平台。也就是说,在使用MinGW或Cygwin编译的C ++项目中使用这些COM类,或者甚至将Wine的GCC端口编译为linux(将Win32编译为在Linux上本机运行的二进制)。
我使用此驱动程序取得了一些有限的成功,但这不成功在100%的情况下(我不能使用由某些方法返回的COM对象)。
有人在类似的情况下有成功吗?
在非Microsoft编译器中调用OLE / COM时,我设法找到完美库: disphelper 。(可从 sourceforge 在允许的BSD许可下)。
在C和C ++(以及任何其他语言与C绑定以及)。它使用类似printf / scanf的格式字符串语法。 (您传递任何您想要的,只要您在格式字符串中指定它,不同于 XYDispDriver ,它需要参数完全匹配任何在类型库中指定的)。
我修改了一点,得到它也编译在Linux下与WineGCC从Win32代码生成本机Linux elf),并自动处理by ref调用(stock disthelper需要程序员设置他/她自己的VARIANT)。
我修补的版本和补丁可以作为github上的fork:
- github/DrYak/disphelper
这里我的补丁:
-
补丁
-
拆分来源的补丁
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)
发布评论