do LPCWSTR support + , these 2 operator?

LPCWSTR

can i do this
1
2
3
4
5
6
string g1= "am";
string g2= "SAD";


LPCWSTR hgc = ("I" + "g1",g2 );


if i can't,
how to convert string to LPCWSTR?

i need to change
string which support + , operator
to
LPCWSTR (use API)


thanks
Last edited on
LPCWSTR are wide character strings, so you can convert from stl in this way:
1
2
wstring g1 = L"am", g2 = L" HAPPY";
LPCWSTR hgc = ( L"I " + g1 + g2 ).c_str();
thanks very much

how about string to LPCSTR

i need to convert it to use

MessageBox(

HWND hWnd, // handle of owner window
LPCTSTR lpText, // address of text in message box
LPCTSTR lpCaption, // address of title of message box
UINT uType // style of message box
);
That is the same but with normal characters, you just need to remove the W and the L
eg:
1
2
string g1 = "am", g2 = " HAPPY";
LPCSTR hgc = ( "I " + g1 + g2 ).c_str();
thanks

LPCTSTR,
C stand for const,
str stand for string

what is t stand for?
T stands for TCHAR (as opposed to char or wchar_t).

On Windows, a TCHAR is either char or wchar_t depending on whether or not UNICODE is #defined by the preprocessor. The idea is that this lets you have separate ANSI and Unicode builds while all sharing the same code.

I have no idea what the T in TCHAR is supposed to stand for, though.
i have somewhere see before , when using unicode , it will have some problem , unless u set something,

do anyone know?

and i still encount error of compile.
1
2
3
4
5
6
7

#include <string>
#include <string.h>
#ifdef _UNICODE
string filename = (cur_dir , ":\\expggds\\" + filename2) ;
LPCTSTR filename_LP = filename.c_str();

error C2440
'initializing' : cannot convert from 'const char *' to 'LPCTSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

my project setting is using unicode, DYNAMIC LINK TO DLL,
SOMEONE SAID using unicode, the program will run faster in win xp, as all they will convert to unicode before running~ ~
Last edited on
anybody can help , i am step on thisd question, in a urgent ~ ~
thanks
'string' uses char
LPCTSTR uses TCHAR

if UNICODE or _UNICODE is defined (which seems to be the case here, TCHAR=wchar_t)

Basically your 'filename_LP' uses wchar_t and your 'filename' uses char.

string -> LPSTR/LPCSTR
wstring -> LPWSTR/LPCWSTR

I don't think there's a build in 'tstring' which uses tchars, but you can make your own easily enough:

1
2
3
4
5
#if defined(UNICODE) || defined(_UNICODE)
typedef wstring  tstring;
#else
typedef string tstring;
#endif 
do u mean the problem come form
1
2
string filename = (cur_dir , ":\\expggds\\" + filename2) ;
LPCTSTR filename_LP = filename.c_str();


string uses char ;
LPCTSTR uses TCHAR ; --> due to i use unicode --> LPCTSTR -> TCHAR -> wchar_t

so , i can not put filename(string, char, ANSI) to filename_LP (LPCTSTR , TCHAR, unicode, wchar_t)

char_t -->wchar_t

it's all about space probelm / wchar_t and char problem

T stands for TCHAR. On Windows, a TCHAR is either char or wchar_t , which depending on do UNICODE is #defined by the preprocessor ~~

The idea is it lets you to use a same variable , before u don't know whether user will input a ANSI or Unicode characters.

1. std::string is ansi and std::wstring is its UNICODE counter part.
2. When unicode is defined, LPCTSTR stands for wchat_t.
3. That's why I have error in line - LPCTSTR filename_LP = filename; i.e. Unicode = Ansi

just have a note of it ,
thanks all of you


Last edited on
if all use wchar_t, wstring, LPCWSTR, unicode then no problem , does it?
now my code change to below:

1
2
3
4
5

TCHAR cur_dir[MAX_PATH];
success = GetCurrentDirectory(MAX_PATH,cur_dir ); 
wstring filename2  = ( L"Stable.txt") ;
wstring filename = (cur_dir ,  L":\\expert\\" , filename2) ;  
Last edited on
You're using TCHAR with wstring. In ANSI build (UNICODE or _UNICODE not defined) that will screw up. You should use wchar_t or WCHAR instead. You're also using the TCHAR version of the function (GetCurrentDirectory). To Get Ansi or Unicode versions of the function, simply put A or W at the end of the function name (GetCurrentDirectoryA for ANSI, GetCurrentDirectoryW for Unicode)

If you're never planning a non-Unicode build, then the code you listed there would work fine. But if you want consistency...

ANSI:
1
2
3
char cur_dir[MAX_PATH];
success = GetCurrentDirectoryA( MAX_PATH, cur_dir );
string filename2 = "Stable.txt";


'Unicode':
1
2
3
wchar_t cur_dir[MAX_PATH];
success = GetCurrentDirectoryW( MAX_PATH, cur_dir );
wstring filename2 = L"Stable.txt";


'TCHAR':
1
2
3
TCHAR cur_dir[MAX_PATH];
success = GetCurrentDirectory( MAX_PATH, cur_dir );
tstring filename2 = _T("Stable.txt");


Note you're responsible for defining 'tstring' yourself. See my previous post.

The _T macro would be put around string literals and makes them wide characters (adds the prefixed L) in Unicode build, or does nothing to them (leaving them normal chars) in ANSI build.

Windows.h basically has a big section where it separates ANSI and Unicode functions and types. It probably looks something like this:

1
2
3
4
5
6
7
8
9
10
#if defined(UNICODE) || (_UNICODE)
  #define TCHAR wchar_t

  #define GetCurrentDirectory  GetCurrentDirectoryW

#else
  #define TCHAR char

  #define GetCurrentDirectory  GetCurrentDirectoryA
#endif 



But ANYWAY. All that whoopla aside. Things are a bit easier if you just make things Unicode all the time. IE: always use wchar_t (or WCHAR if you prefer), wstring, LPWSTR, LPCWSTR, and the 'W' family of WinAPI functions and structs. There isn't really much point in doing non-Unicode windows builds these days.
Set Compiler options. Use unicode or mutiplebyte, then, macro "UNICODE" and "_UNICODE" will be defined or not at compiling.
Generally, c++ check the "_UNICODE" and that windows check the "UNICODE".

"T" means type I think, a auto type at compiling.
1
2
3
4
5
6
7
8
9
10
int main(int argc, char* argv[])
{        

		LPCWSTR g1 , g2 ;
		g1 = L"jsfgv3";
		g2 = L"sjgvy";

		LPCWSTR g3 = (& g1 + & g2);  error C2110: '+' : cannot add two pointers
}


i find out i cannot use "+" to add 2 pointer , that means LPWTR do not spport +

and
1
2
3
4
5
6
7
8
9
10
11
12
int main(int argc, char* argv[])
{

        
      LPWSTR g1 , g2 ;
      g1 = L"jsfgv3";
     g2 = L"sjgvy";

   LPWSTR g3 = (g1,g2);
	printf("Hello World!\n");
	return 0;
}


g3 just have the value of g2, which is only the value of last parameter

so LPWSTR does not support "," to joint 2 LPWSTR
LPWSTR g3 = ( (LPWSTR)&g1, (LPWSTR)&g2 );

maybe it works~ ~
Last edited on

Bazzy (1746) Jun 16, 2009 at 9:39pm
LPCWSTR are wide character strings, so you can convert from stl in this way:

wstring g1 = L"am", g2 = L" HAPPY";
LPCWSTR hgc = ( L"I " + g1 + g2 ).c_str();



STL: ST stand for STring, L stand for Library, right?

ATL : stand for Algorithms of Library // about maths
STL: Standard Template Library.
ATL: ActiveX Template Library.

Google it please :).
LPSTR/LPCSTR/LPWSTR/LPCWSTR/LPTSTR/LPCTSTR are not new types like std::string is... and so they do not have , or + operators overloaded. They are simply typedefs (or really #defines) of char*, wchar_t*, and TCHAR* (and the respective const versions).
Try using strcat().
Topic archived. No new replies allowed.