VS2012中使用(#import导入)tlb文件
来源:互联网 发布:程序员哄抢猝死险 编辑:程序博客网 时间:2024/06/06 03:54
虽然作为VC++用户,生成tlb文件后我们可以直接使用当时生成的*_i.h与*_i.c文件,这样确实方便。不过既然Microsoft提供了#import方法,那我还是试试吧。
参考:
#import与#include或者#import *.dll VS #import *.tlb的差异:
forums.codeguru.com/showthread.php?376416-What-is-the-difference-between-import-and-include
#improt用法:http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx
环境:VS2012 , Win8.1 64bit CS
项目环境:
ATLProject1负责提供com接口IFun并生成tlb,生成目录指定为demo\debug
MFCApplication1负责导入tlb,生成目录指定为demo\debug
步骤:
1. 生成tlb文件,略
2. 添加"demo\debug"到MFCApplication1的"VC++目录"->"库目录" (VS会搜索*.tlb文件)
3. MFCApplication1的stdafx.h里添加 引用语句
4. 按照传言,我们需要编译一次MFCApplication1,这样会才会生成tlh与tli文件,而这2个文件相当于头文件与实现。
经过实验与理解,我们不应该#include "*.tlh"文件,因为在compile时VS会自动把刚在‘中间目录’生成的*.TLH/*.TLI代码包含进我们的源码。如果#include *.tlh,反而不对。
(关于tlh与tli是干什么的,MSDN里已经提到了:#importcreates two header files that reconstruct the type library contents in C++ source code. The primary header file is similar to that produced by the Microsoft Interface Definition Language (MIDL) compiler, but with additional compiler-generated code and data. Theprimary header file has the same base name as the type library, plus a .TLH extension. The secondary header file has the same base name as the type library, with a .TLI extension. It contains the implementations for compiler-generated member functions, and is included (#include) in the primary header file.)
5. VS的Inteligense提示接口没有定义
6. 添加完后发现还是提示”未定义标识符“,指明接口未定义,原来#import时自动给我的接口加上了namespace。
所以我们要把第3步改为#import "ATLProject1.tlb" no_namespace, 然后重新编译生成*.tlh与*.tli。如此我们才能在代码中使用IFun接口而不报错.
当然也可以using namespace 自动生成的namespace名字,就不加no_namespace了
7. 如果过段时间*.TLB文件更新了,我们要更新自己的项目。clean项目,VS的inteligense也会提示接口没有定义,没关系,编译项目生成新的*.TLH、*.TLI文件继续写。
8. 推荐: 我们可以把#import放进stdafx.h里,然后编译stdafx.cpp,这样也会生成*.TLH/*.TLI文件,而且更方便。
- VS2012中使用(#import导入)tlb文件
- C++中导入tlb文件
- VS2012中查看*.tlb所包含信息
- 【转】 #import ; tlb, tlh, tli 文件
- COM组件 #import ; tlb, tlh, tli 文件
- COM组件 #import ; tlb, tlh, tli 文件
- python使用import导入文件夹中的文件
- 在vc++工程中只使用tlb文件的用法
- ocx控件 tlb文件 使用
- xcode的工程文件怎么导入到vs2012中
- 使用@import url()对资源文件进行导入
- 使用cocoapods import头文件导入不提示解决方法
- 使用IDL创建TypeLib(.tlb)文件
- #import "..\Simple3\Simple3.tlb" no_namespace
- tlb tlh tli文件(COM)
- tlb tlh tli文件(COM)
- Python中关于导入(import)语句的使用说明
- vs2012 中使用 gtest
- 安码招投标系统
- GitHub详细教程
- IOS 日期格式转换
- STM32——C语言数据类型
- oracle
- VS2012中使用(#import导入)tlb文件
- Java中构造方法、实例方法、类方法的区别
- cuda6.5 deviceQuery.exe
- MongoDB学习笔记<五>
- 理解typedef
- js检查元素是否包含在数组中
- 学习!
- extend与implements的区别
- 在linux系统出现“Sudo提权出现:xx用户不在sudoers文件中解决”