Skip to main content
GameDev.net gamedev.net
🔒 Locked

Code Project: CHighTime error under VS2008+

Started by IADaveMark Jan 12, 2010 at 8:33 PM 11 replies 4.3k views
Original Post
IADaveMark
IADaveMark
OK folks... mystery solving time. I have an extensive project that makes use of this little gem from CodeProject. CHighTime
Quote:
The CHighTime and CHighTimeSpan are two classes for replacement of COleDateTime and COleDateTimeSpan. Instead of using a double for storing the date, it uses a 64 bit integer to store the date and time. The range is +/-29000 years and the smallest time span is 0.1 microseconds.
This worked admirably when compiled under older versions of VS. However, when I upgraded to VS 2008, it blew up. The errors and their respective code chunks are listed here:

int CHighTime::FindStr(LPCTSTR pszSource, LPCTSTR pszSub, int nStart)
{
	int nLength = strlen(pszSource); // <-------- error 3
	if (nStart > nLength)
		return -1;

	// find first
	LPCTSTR pszSearch = strstr(pszSource + nStart, pszSub); // <--- error 4

	// return -1 for not found
	return (pszSearch == NULL) ? -1 : (int)(pszSearch - pszSource);
} // CHighTime::FindStr()

Error 3 error C2664: 'strlen' : cannot convert parameter 1 from 'LPCTSTR' to 'const char *' Error 4 error C2665: 'strstr' : none of the 2 overloads could convert all the argument types

int CHighTime::ReplaceStr(LPSTR pszDest, int nDestSize, LPCTSTR pszMask, LPCTSTR pszSource)
{
    int nCount, iInsertLen, iReplaceLen, iMoveLen, iDestLen;
    LPSTR pSearch, pStartPos;

    nCount = 0;
    pStartPos = pszDest;
    while ( (pSearch = strstr(pStartPos, pszMask)) != NULL) { // <--- error 5
        pStartPos = pSearch + 1;
        ++nCount;
    }

    if (nCount > 0) {

        iReplaceLen = strlen(pszMask);
        iInsertLen = strlen(pszSource);

        // Can destination take the target?
        if ((int)strlen(pszDest) + nCount*(iInsertLen - iReplaceLen) > nDestSize) 
            return 0; // no => do nothing

        iDestLen = strlen(pszDest);
        pStartPos = pszDest;
        while ( (pSearch = strstr(pStartPos, pszMask)) != NULL) {
           
            iMoveLen = iDestLen - (pSearch - pszDest);
            if (iReplaceLen != iInsertLen ) {
                memmove(pSearch + (iInsertLen - iReplaceLen), pSearch, iMoveLen);
                iDestLen += iInsertLen - iReplaceLen;
                pszDest[iDestLen] = '\0';
            }
            memcpy(pSearch, pszSource, iInsertLen);

            pStartPos = pSearch + 1;
        }
    }
    return nCount;
} // CHighTime::ReplaceStr()

Error 5 error C2665: 'strstr' : none of the 2 overloads could convert all the argument types Error 6 fatal error C1903: unable to recover from previous error(s); stopping compilation If you need any more information on what's going on, let me know and I can paste a few other bits. On the other hand, if you want to get dirty, the files are small and easily inserted into a blank MFC app in VS 2008. I would really hate to rip this class out and make my project work with something else. I figure the error should be simple enough, but I just can't wrap my brain around it. Thanks folks...
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
Antheus
Antheus
LPCTSTR - Long Pointer to const TCHAR String.

What is your TCHAR defined as? If using unicode, then it will be wchar_t.

So either disable unicode in the project, or use the w_ versions of string methods.
IADaveMark
IADaveMark
Have I told you lately that I loved you? That I love this community? That I love all of society and the beasts of the forests and... *ahem*

Either of you two going to GDC? Someone gets a free beer.
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
nobodynews
nobodynews
It is probably a Unicode issue. strlen is for multibyte (ASCII) and you probably have wide characters (Unicode) enabled. That is, LPCTSTR is probably being expanded to wchar_t*. You can probably just change strlen to _tcslen according to here.
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,
ChaosEngine
ChaosEngine
Antheus is right. I believe Character Set (Project Properties->Configuration Properties->General->Character Set) is set to "Use Unicode Character Set" by default in vs2008. Unless you need unicode, you can change it to "Use Multi-Byte Character Set" and it should fix the problem.

edit: ok, seriously ninja'd [sad]
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
IADaveMark
IADaveMark
Sorry guys... just because you answer this thread with the same answer doesn't mean that you ALL get a beer!
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
iMalc
iMalc
I also knew the answer the moment I reached that part of the post.
I can also tell you that at my work we also have a well written replacement for those classes that use a 64-bit integer internally, which I unfortunately am not able to share. Good to know that other's have the same requirements.

Glad someone else could help you sooner than I could. Don't worry, I don't drink anyway...
nobodynews
nobodynews
Quote:
Original post by InnocuousFox
Sorry guys... just because you answer this thread with the same answer doesn't mean that you ALL get a beer!

But! But! I posted a more generic solution! _tcslen will work regardless of unicode settings!


!!!
C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) ,
ChaosEngine
ChaosEngine
Quote:
Original post by InnocuousFox
Sorry guys... just because you answer this thread with the same answer doesn't mean that you ALL get a beer!


wait, there was beer on offer? and no there's .... no beer?[bawling]
if you think programming is like sex, you probably haven't done much of either.-------------- - capn_midnight
IADaveMark
IADaveMark
Just because I offered a GDC beer to the first responders doesn't mean this is now a sign-up list! ;-)
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<
IADaveMark
IADaveMark
Quote:
Original post by evolutional
Someone say beer?


*sigh*
Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit<

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.