查看单个帖子
旧 2009-03-22, 10:51 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 【转帖】bug分析

VS2005环境ATL工程报错:error C2065: “_Module”: 未声明的标识符
写在前面:
最近在接触office编程,使用vc6.0环境Debug能编译通过,但是ReleaseUMinDependenc编译就报错libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _这个问题还没有解决。希望通过CSDN有高手指点,日后再总结6.0环境这个问题。高手门都建议学习ATL COM最好使用VS2005。折腾半天还是遇见这个错误,这个错误又折腾半天!通过Google有问题你就个google)找到CSDN有朋友遇见同样的问题!他的描述如下也是我要表达的):
VC6.0中用ATL生成的全局变量_Module,
CComModule _Module;
可以调用_Module.GetResourceInstance();

用VS2005生成时为_AtlModule,
COutLookAddinModule _AtlModule
不能调用GetResourceInstance();怎么办?
在所有回复中没有找到答案!但是通过QQ技术群平台和Google还有百度找到一些方向!
1、VS2005的wizard生成ATL后,发现VS2005会用子类模板化的_AtlModule代替原来VC6.0的_Module
2、VS2005中 ATL 7.0取代了vc6.0中的 ATL 3.0。
3、MSDN英文中有提到CAtlBaseModule Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.
也就是说要使用GetResourceInstance(); 必须派生于CAtlBaseModule 。结果自作聪明到处定义CAtlBaseModule _Module。结果有不少新的错误!还好我在CSDN发帖有问直接告诉我了!直接使用_AtlBaseModule,微软已经为我们定义好了!在atlcore.h定义了extern CAtlBaseModule _AtlBaseModule;
示例如下:


// 设置位图按钮风格,位图为x32大小,将其放入剪切板中用PasteFace()贴在指定按钮上
HBITMAP hBmp =(HBITMAP)::LoadImage(_AtlBaseModule.GetResourceInstance(),
MAKEINTRESOURCE(IDB_BITMAP),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);

附一:
Earlier versions of ATL used CComModule. In ATL 7.0, CComModule functionality is replaced by several classes:

CAtlBaseModule Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.

CAtlComModule Contains information required by the COM classes in ATL.

CAtlWinModule Contains information required by the windowing classes in ATL.

CAtlDebugInterfacesModule Contains support for interface debugging.

CAtlModule The following CAtlModule-derived classes are customized to contain information required in a particular application type. Most members in these classes can be overridden:

CAtlDllModuleT Used in DLL applications. Provides code for the standard exports.

CAtlExeModuleT Used in EXE applications. Provides code required in an EXE.

CAtlServiceModuleT Provides support to create Windows NT and Windows 2000 Services.

CComModule is still available for backward compatibility.
Earlier versions of ATL used CComModule. In ATL 7.0, CComModule functionality is replaced by several classes:

CAtlBaseModule Contains information required by most applications that use ATL. Contains the HINSTANCE of the module and the resource instance.

CAtlComModule Contains information required by the COM classes in ATL.

CAtlWinModule Contains information required by the windowing classes in ATL.

CAtlDebugInterfacesModule Contains support for interface debugging.

CAtlModule The following CAtlModule-derived classes are customized to contain information required in a particular application type. Most members in these classes can be overridden:

CAtlDllModuleT Used in DLL applications. Provides code for the standard exports.

CAtlExeModuleT Used in EXE applications. Provides code required in an EXE.

CAtlServiceModuleT Provides support to create Windows NT and Windows 2000 Services.

CComModule is still available for backward compatibility.

附二(写在前面提及的错误,目前还没有找到答案!贴出来希望有高手能指点):
ATL 工程 中ReleaseUMinDependency与 Debug区别是什么?
Debug可以编译通过
ReleaseUMinDependency编译报错
Linking...
Creating library ReleaseUMinDependency/WordCOM.lib and object ReleaseUMinDependency/WordCOM.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseUMinDependency/WordCOM.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

WordCOM.dll - 2 error(s), 0 warning(s)

注意:
查资料反馈
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
这个错误的修改方法如下:
Windows项目要使用Windows子系统, 而不是Console, 可以这样设置
[Project] --> [Settings] --> 选择"Link"属性页
在Project Options中将/subsystem:console改成/subsystem:windows

可是我这边这个参数没有错:
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /incremental:no /pdb:"ReleaseUMinDependency/OutLookAddin.pdb" /machine:I386 /def:".\OutLookAddin.def" /out:"ReleaseUMinDependency/OutLookAddin.dll" /implib:"ReleaseUMinDependency/OutLookAddin.lib"
是不是因为我的工程不是 MFC而是ATL,还有其他地方有错误!
第2个错误也没有找到具体的静态库!
希望大家帮帮我!
基本完成office编程(Outlook)的示例程序link
__________________
借用达朗贝尔的名言:前进吧,你会得到信心!
[url="http://www.dimcax.com"]几何尺寸与公差标准[/url]
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)