如何调用在C COM组件 [英] How to call a COM component in C
问题描述
我要调用从C在Visual Studio中做了一个COM组件。我能够从的Visual C ++调用它使用#进口'指令通过指定.tlb文件。但我不认为在C语言中#import指令。有没有我可以改用那别的选择吗?
I have to call a COM component from C done in Visual Studio. I am able to call it from Visual C++ using the '#import' directive by specifying the .tlb file. But I don't see #import directive in the C language. Is there an alternative I can use instead of that?
我不能用C ++写的,因为我有创造纯C只。
I cannot write in C++ as I have to create the module in pure C only.
推荐答案
在该组件的类型库可能来源于MIDL编译IDL文件。 MIDL生成三个文件 - .TLB,.C和.h。 .c和.h文件包含对C的和的C ++接口定义 - 有一个极大数的#ifdef __cplusplus
来提供相同的定义 - 一组是C和另一个是C ++。
The type library in that component likely comes from compiling a IDL file by MIDL. MIDL produces three files - .tlb, .c and .h. .c and .h files contain interface definitions for C and C++ - there's a gazillion of #ifdef __cplusplus
to provide identical definitions - one set is for C and another one is for C++.
您必须让那些.c和.h文件,包括到您的项目。如果你有COM组件的来源 - 获得这些文件构建组件后。如果它是由第三方发货 - 与他们联系,并要求他们公布这些文件
You have to get those .c and .h files and include into your project. If you have the COM component sources - get those files after building the component. If it's shipped by a third party - contact them and ask them to publish those files.
这篇关于如何调用在C COM组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!