请教ATL数据库操作问题
--------------------Configuration: AccountSvr - Win32 Debug--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164  
Copyright (c) Microsoft Corp 1991-1997. All rights reserv
...............
Linking...
   Creating library Debug/AccountSvr.lib and object Debug/AccountSvr.exp
Performing registrationAccountSvr.dll - 0 error(s), 1 warning(s)
--------------------Configuration: AccountSvr - Win32 Unicode Debug--------------------
Creating Type Library...
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\urlmon.idl
urlmon.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\msxml.idl
.......................
Linking...
   Creating library DebugU/AccountSvr.lib and object DebugU/AccountSvr.exp
Performing registrationAccountSvr.dll - 0 error(s), 1 warning(s)
--------------------Configuration: AccountSvr - Win32 Release MinSize--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164  
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
................................
Linking...
   Creating library ReleaseMinSize/AccountSvr.lib and object ReleaseMinSize/AccountSvr.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseMinSize/AccountSvr.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.AccountSvr.dll - 2 error(s), 1 warning(s)
--------------------Configuration: AccountSvr - Win32 Release MinDependency--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164  
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
....................................
Linking...
   Creating library ReleaseMinDependency/AccountSvr.lib and object ReleaseMinDependency/AccountSvr.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseMinDependency/AccountSvr.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.AccountSvr.dll - 2 error(s), 1 warning(s)
--------------------Configuration: AccountSvr - Win32 Unicode Release MinSize--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164  
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
.............................
Linking...
   Creating library ReleaseUMinSize/AccountSvr.lib and object ReleaseUMinSize/AccountSvr.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseUMinSize/AccountSvr.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.AccountSvr.dll - 2 error(s), 1 warning(s)
--------------------Configuration: AccountSvr - Win32 Unicode Release MinDependency--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164  
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
.....................
Linking...
   Creating library ReleaseUMinDependency/AccountSvr.lib and object ReleaseUMinDependency/AccountSvr.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseUMinDependency/AccountSvr.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.AccountSvr.dll - 2 error(s), 1 warning(s)为啥在编译时Debug可以通过,-------Release不能通过
如果去掉m_pConnection->Open((const char *)connectBuffer,"","",-1);
在编译时Debug和Release都可以通过

解决方案 »

  1.   

    选定相应的RELEASE版本,在项目设置中,
    Project->setting->C++->PreProcessorPreProcessor Definitions中, 去掉_ATL_MIN_CRT.
      

  2.   

    这是因为#import生成的_com_ptr_t类的派生类(即smart pointer)中,有抛出C++异常的实现,而C++异常是需要C运行时库的,所以会报找不到_main的错。解决方法一个是按楼上所说的,但这样会使你的组件比较大。别一个方法,请参考MSDN中“Compiler COM Support Classes“,自定义一个_com_raise_error,这样在灵巧指针实现的方法内部就不会抛出C++异常了。但是最好只用#import生成的smart pointer的原生方法,因为被_com_ptr_t包装的方法参数里有用_bstr_t包装BSTR的情况,面_bstr_t内容直接用throw抛出C++异常。例如你用(假设pCn是_Connection的smart pointer)pCn->raw_Open(...)就不会链接C运行时库,而用pCn->Open里面可能抛出C++异常。
      

  3.   

    horris(僧推月下门)讲的方法如何实现???
      

  4.   

    自定义一个_com_raise_error,实现的方法不会抛出C++异常了。用#import生成的smart pointer的原生方法,因为被_com_ptr_t包装的方法参数里有用_bstr_t包装BSTR的情况,面_bstr_t内容直接用throw抛出C++异常。例如你用(假设pCn是_Connection的smart pointer)pCn->raw_Open(...)就不会链接C运行时库,而用pCn->Open里面可能抛出C++异常。
    horris(僧推月下门)讲的方法如何实现???
      

  5.   

    horris(僧推月下门)讲的方法如何实现???
    给个例子好吗?:)
    我是菜鸟+懒人!