🔒 Locked
String to LPCTSTR
Advertisement
Original Post
LongPointertoCharacTerSTRing. Not sure what you're trying to do, but either use the old style cast
somethinglikethis = (LPCTSTR) somethinglikethat;
or the dynamic cast
somethinglikethis = dynamic_cast < LPCTSTR > somethinglikethat;
Leave out the spaces between the chevrons.
Beginners and experts will find answers here.
[edited by - mathematix on August 21, 2003 8:47:31 AM]
somethinglikethis = (LPCTSTR) somethinglikethat;
or the dynamic cast
somethinglikethis = dynamic_cast < LPCTSTR > somethinglikethat;
Leave out the spaces between the chevrons.
Beginners and experts will find answers here.
[edited by - mathematix on August 21, 2003 8:47:31 AM]
quote:
Original post by Mathematix
or the dynamic cast
somethinglikethis = dynamic_cast < LPCTSTR > somethinglikethat;
ROFL.
No, you don't need any cast:
const char* str1 = "blergh";
char* str2 = "blah";
LPCTSTR str3 = str1;
LPCTSTR str4 = str2;
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
[edited by - Lektrix on August 21, 2003 8:59:21 AM]
What kind of string are you talking about?
std::string or (c-style) char*-string?
In case of std::string call the .c_str() member-function
A little more info:
[edited by - Wildfire on August 21, 2003 9:01:08 AM]
std::string or (c-style) char*-string?
In case of std::string call the .c_str() member-function
A little more info:
// WinNT.h
typedef CONST CHAR *LPCSTR, *PCSTR;
typedef CONST WCHAR *LPCWSTR, *PCWSTR;
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
#else
typedef LPCSTR LPCTSTR;
#endif
[edited by - Wildfire on August 21, 2003 9:01:08 AM]
quote:
Original post by Mathematix
or the dynamic cast
somethinglikethis = dynamic_cast < LPCTSTR > somethinglikethat;
dynamic_cast is only for base-to-derived casts of polymorphic classes and is completely inappropriate here.
kobingo - I assume that, by string, you mean a C++ std::string object. Two possibilities :
- You are only going to read the string at a single point - which appears to be the case with D3DXCreateTextureFromFile. If so, you can use the std::string::c_str() member function.
SomeFunction( MyString.c_str() ); - You need to create a C string out of the string object in a persistent manner - by copying it out in a char buffer. If so, you can use the std::string::copy() member function.
char* buffer = new char[MyString.length()+1];
MyString.copy( buffer, std::string::npos );
buffer[MyString.length()] = 0;
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
quote:
Original post by kobingo
(that is what the D3DXCreateTextureFromFile wants)
My guess is that he is only going to need
std::string::c_str(). [ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]
Okay, guys.
I put up some possible solutions. No code samples provided, so I put down some possibilities - OKAY?!
Bloody hell!!! >
Beginners and experts will find answers here.
I put up some possible solutions. No code samples provided, so I put down some possibilities - OKAY?!
Bloody hell!!! >
Beginners and experts will find answers here.
quote:
Original post by Mathematix
LongPointertoCharacTerSTRing
Actually that''s
Long Pointer to Const T STRing
Qui fut tout, et qui ne fut rien
Invader''s Realm
You guys are really taking the p*** now, but I ain''t trippin''.
Beginners and experts will find answers here.
Beginners and experts will find answers here.
quote:
Original post by Anonymous Poster
just to add fuel to the firethe T stands for TCHAR, which is associated with MS''s tchar.h #defines that help create "portable" code that can be used to target both ANSI and UNICODE character set based versions of Windows without recoding.
Aye. For "null-terminated" it''s a "Z"
quote:
Original post by Anonymous Poster
so, me being a C++ lib no-nothing, will MS''s implementation of std::string have c_str() return a pointer to a wide (2 byte) character buffer if a UNICODE char set is targeted for the build? according to the MSDN docs it will return a pointer to a nonmodifiable C string, which doesn''t tell me much.
That''s the decisive question.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement