简体   繁体   中英

Why can't I call CTime::GetAsDBTIMESTAMP with Visual Studio 2013?

I create a new Visual C++ Win32 Project in Visual Studio 2012 - just a console application with a precompiled header. I add an include for atltime.h and three lines of code to _tmain :

// timeapp2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "atltime.h"

int _tmain(int argc, _TCHAR* argv[])
{
    CTime c = CTime::GetCurrentTime();
    DBTIMESTAMP t;
    c.GetAsDBTIMESTAMP(t);
    return 0;
}

I compile it. It compiles fine.

I try the same thing in Visual Studio 2013. I get the following errors:

Error   1   error LNK2019: unresolved external symbol "public: bool __thiscall ATL::CTime::GetAsDBTIMESTAMP(struct tagDBTIMESTAMP &)const " (?GetAsDBTIMESTAMP@CTime@ATL@@QBE_NAAUtagDBTIMESTAMP@@@Z) referenced in function _wmain c:\tmp\timeapp\timeapp2\timeapp2.obj    timeapp2

Error   2   error LNK1120: 1 unresolved externals   c:\tmp\timeapp\Debug\timeapp2.exe   1   1   timeapp2

This is a fresh installation of Visual Studio Premium 2013 Update 2 taken from MSDN subscriber downloads. I have tried the same thing on two seperate machines, one running Windows 8.1 x64, and the other running Windows Server 2012 R2. Both fail to compile using Visual Studio 2013.

What am I doing wrong?

You are missing the ATL library.

(The following is for VS2008, sorry for my old environment - but I'd expect you can find the options in similar locations):

When creating the project , select "add general ATL headers"

Alternatively under Project Configuratrion / General, enable "Use of ATL" (either static or dynamic, dynamic gives a smaller executable but you need the respective ATL runtime in manifest and installed on the target)


[edit]
You can try to add the respective ATL lib manually to the linker (atl{s}{d}.lib, use 's' for static, 'd' for debug build). Haven't done ATL under VS2013 yet, so these are just "educated guesses".


If it's just this one call, you could also just use GetSystemTime, and then fill the DBTIMESTAMP structure.

(shameless plug: or, if you are coming from CTime, which is just a wrapper for _time64_t see here for conversion time_t --> SYSTEMTIME)

This has been confirmed as a bug in Visual Studio 2013, and will be fixed in the next version. From the Microsoft Connect page :

Thanks for reporting this bug! I'm working on a fix now. This will be resolved in the next release of VS.

Artur Laksberg, VC++ Libraries Team

For now, we can use the following workaround which was posted on the Connect page:

CTime c = CTime::GetCurrentTime();
DBTIMESTAMP d;
COleDateTime(c.GetTime()).GetAsDBTIMESTAMP(d);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM