convert stl string to a LPTSTR

I need to pass a stl string to a function that takes a LPTSTR.  I've tried:

string junk1 = "howdy";

TextOut(dc, RectLeft, RectTop, (LPTSTR) junk1.c_str, 5);

but it doesn't compile.
abulkaAsked:
Who is Participating?
 
chensuConnect With a Mentor Commented:
You use c_str() for GetTextExtentPoint32 while you use c_str for TextOut.
0
 
chensuCommented:
junk1.c_str()

Note that it won't compile for Unicode version.
0
 
abulkaAuthor Commented:
Actually how come

  string text1 = "hello";
  SIZE res;
  GetTextExtentPoint32(rDC.m_hDC, text1.c_str(), (int) text1.length(), &res);

works, but

  TextOut(rDC.m_hDC, RectLeft, RectTop,  text1.c_str, (int) text1.length());

does not?  The error is
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(644) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'const char *(void) const' to 'const char *'
        There is no context in which this conversion is possible
D:\My Documents\aa Vc\ts1\CNodeView1.cpp(653) : error C2664: 'TextOutA' : cannot convert parameter 4 from 'const char *(void) const' to 'const char *'
        There is no context in which this conversion is possible

Note the definitions in the API

BOOL GetTextExtentPoint32(

    HDC hdc,      // handle of device context
    LPCTSTR lpString,      // address of text string
    int cbString,      // number of characters in string
    LPSIZE lpSize       // address of structure for string size  
   );      
 
and

BOOL TextOut(

    HDC hdc,      // handle of device context
    int nXStart,      // x-coordinate of starting position  
    int nYStart,      // y-coordinate of starting position  
    LPCTSTR lpString,      // address of string
    int cbString       // number of characters in string
   );      
 

the relevant parameter is the same - a LPCTSTR.


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
abulkaAuthor Commented:
Adjusted points from 5 to 10
0
 
abulkaAuthor Commented:
How do I know if unicode affects me?  Is it a compiler switch?  What stops working in unicode mode?
0
 
abulkaAuthor Commented:
See my second & third comments for better context for the required answer.
0
 
abulkaAuthor Commented:
Adjusted points from 10 to 20
0
 
chensuCommented:
Clear enough?

You miss out ().
0
 
abulkaAuthor Commented:
Yeah - they should both be .c_str()
Thanks.
0
All Courses

From novice to tech pro — start learning today.