CString -- ATL::CStringT<char, StrTraitMFCDLL format problem

Noah Aas 685 Reputation points
2025-03-11T14:38:03.34+00:00

Hello, I got this warning. https://learn.microsoft.com/en-us/cpp/code-quality/c6284?view=msvc-160

CString Logging::AddEntry(CString strEntry)
{
	SYSTEMTIME stTimestamp;
	CString    strNewEntry = _T("");
	CString    strTempEntry = strEntry;
	CString    strTempOldFile = _T("");
	if (m_bWithTimestamp)
	{
		GetLocalTime(&stTimestamp);
		strNewEntry.Format(_T("[%02d:%02d:%02d.%003d] %s\r\n"), stTimestamp.wHour, stTimestamp.wMinute, stTimestamp.wSecond, stTimestamp.wMilliseconds, strTempEntry);
	}
	// Neuer Eintrag ohne Zeitstempel
	else
	{
		strNewEntry.Format(_T("%s\r\n"), strTempEntry);
	}

enter image description here

How can I solve it? What is wrong? I need only CString and ANSII coding. No unicode.

framework.h    stdafx.h
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#define _AFX_ALL_WARNINGS

#include <afxstr.h>
#include <atlbase.h>
#include <string>

#include <afxwin.h>
#include <afxext.h>
#include <afxdisp.h>
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif
#include <afxcontrolbars.h>
#include <afxsock.h>
//https://github.com/microsoft/VCSamples/blob/master/VC2010Samples/MFC/Visual%20C%2B%2B%202008%20Feature%20Pack/OutlookDemo/stdafx.h

Thanks in advance.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,877 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 47,526 Reputation points
    2025-03-11T15:43:52.5466667+00:00

    In the call to CString::Format pass (LPCTSTR) strTempEntry. This will satisfy the compiler that is looking for a char* pointer not a CString object


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.