question

45349313 avatar image
0 Votes"
45349313 asked RLWA32-6355 commented

LPCTSTR to CString. Cast from pointer type const CHAR* is not allowed

JOINT STRIKE FLGHTER, AIR VEHICLE, C++ CODING STANDARDS Chapter 4.23 Type Conversions, AV Rule 182.

How can the conversion be successful?

c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


I do not think that making a CString from 'const CHAR'* represents a conversion in terms of the the AV Rule.


0 Votes 0 ·
RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered RLWA32-6355 edited

Pass the const char* pointer to the narrow string to the CString class constructor.
For example,

 LPCTSTR psz = "narrow string";
 CString str(psz); // Construct CString object
 printf_s("Null terminated string : %s\n", psz);
 printf_s(("CString object : %s\n"), str.GetString());

Another way to construct the CString object-

 CString str = psz; // Construct CString object


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

45349313 avatar image
0 Votes"
45349313 answered RLWA32-6355 commented

@RLWA32-6355

https://www.parasoft.com/


This is the result of checking the code using the c/c++ test tool from parasoft, a reliability test tool company.

The project is set to multibyte.
void foo2(CString strPath)
{
//strPath
}

void foo(LPCTSTR strPath)
{
foo2(CString(strPath)); << this line
}

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Perhaps this is a question that can best be answered by parasoft.

0 Votes 0 ·