tchar

What is the simplest way to convert char[] to/from tchar[] in C/C++(ms)?

爱⌒轻易说出口 提交于 2019-12-17 12:48:44
问题 This seems like a pretty softball question, but I always have a hard time looking up this function because there seem there are so many variations regarding the referencing of char and tchar. 回答1: MultiByteToWideChar but also see "A few of the gotchas of MultiByteToWideChar". 回答2: The simplest way is to use the conversion macros: CW2A CA2W etc... MSDN 回答3: TCHAR is a Microsoft-specific typedef for either char or wchar_t (a wide character). Conversion to char depends on which of these it

Why is PCTSTR not defined but LPCTSTR defined?

南楼画角 提交于 2019-12-13 18:09:27
问题 I have been assigned to update an old code written in MSVC++ 6. I have been getting unknown definition for PCTSTR but it was not defined even if I included the tchar.h. In my previous experience I know there is an LPTSTR but no PCTSTR. I grep the C:\Program Files\Microsoft Visual Studio\VC98\Include\ folder and did not found a definition of PCTSTR. But to my surprise when I searched the Windows SDK folder [C:\Program Files\Microsoft SDK] there was no definition of PCTSTR but it was used in

TCHAR[], LPWSTR, LPTSTR and GetWindow Text function

非 Y 不嫁゛ 提交于 2019-12-13 06:52:20
问题 So the GetWindowText is declared on MSDN as follows: int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount ); However for the code to work we have to declare the second parameter as TCHAR[255] WTitle; and then call the function GetWindowText(hWnd,Wtitle,255); The LPTSTR is a pointer to an array of tchar, so declaring LPTSTR is similar to declaring TCHAR[]? It doesn't work this way though. When using TCHAR[] the program returns valid GetWindowText result (it is an integer equal to the

C++ Combine 2 Tchar

社会主义新天地 提交于 2019-12-10 13:48:21
问题 I'm trying to combine 2 tchar. char username[UNLEN+1]; DWORD username_len = UNLEN+1; GetUserName(username, &username_len); TCHAR* appdatapath ="C:\\Users\\"+username+"\\AppData"; But I get error error at appdatapath line. How can I combine 2 tchar? Thanks 回答1: Have a look at strcat and wcscat. You can't add char pointer with char array. If you are on a windows machine, you can use _tcscat which will redirect to the right function to use depending on _UNICODE and _MBCS defines. Might want to

Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions?

耗尽温柔 提交于 2019-12-10 12:44:13
问题 Is it advisable to use strcmp or _tcscmp for comparing strings in Unicode versions? 回答1: _tcscmp() is a macro. If you define UNICODE it will use wcscmp() , otherwise it will use strcmp() . Note the types TCHAR , PTSTR , etc. are similar. They will be WCHAR and PWSTR if you define UNICODE , and CHAR and PSTR otherwise. 回答2: No, you should use _ tcscmp . That will resolve to proper function depending upon on your compiler flags. 来源: https://stackoverflow.com/questions/2107103/is-it-advisable-to

Why could i get an Unhandled exception Access violation writing in c++/CLI?

烂漫一生 提交于 2019-12-09 19:30:47
问题 I have been struggeling writing a solution excisting out of an c++ win32console and a c++ dll. i finally managed to get them talking without linker errors (so i am assuming both are fully managed c++/CLI projects) but when i run the console i get the following error. Unhandled exception at 0x03f71849 in Company.Pins.Bank.Win32Console.exe: 0xC0000005: Access violation writing location 0x00000001. The console also shows the following Unhandled Exception: System.NullReferenceException: Object

Converting TCHAR to string in C++

对着背影说爱祢 提交于 2019-12-08 14:37:53
问题 I'm trying to convert a TCHAR to a string as in: std::string mypath; TCHAR path[MAX_PATH]; GetModuleFileName( NULL, path, MAX_PATH ); I need to set mypath to that of path . I did a simple loop and concatenated path[index] to mypath and this works but I don't like this way. I'm new to C++ but have done plenty of C#. I've seen examples of the GetModuleFileName that passes in a "char" but it doesn't like it. It needs the TCHAR or a LPWSTR . 回答1: TCHAR is a macro defined as a char or wchar

How to convert std::wstring to a TCHAR*

安稳与你 提交于 2019-12-06 05:19:13
问题 std::wstring.c_str() returns a wchar_t*. How do I get from wchar_t* to TCHAR*, or from std::wstring to TCHAR* Thanks 回答1: #include <atlconv.h> TCHAR *dst = W2T(src.c_str()); Will do the right thing in ANSI or Unicode builds. 回答2: use this : wstring str1(L"Hello world"); TCHAR * v1 = (wchar_t *)str1.c_str(); 回答3: TCHAR* is defined to be wchar_t* if UNICODE is defined, otherwise it's char*. So your code might look something like this: wchar_t* src; TCHAR* result; #ifdef UNICODE result = src;

should I eliminate TCHAR from Windows code?

不问归期 提交于 2019-12-05 03:19:20
I am revising some very old (10 years) C code. The code compiles on Unix/Mac with GCC and cross-compiles for Windows with MinGW. Currently there are TCHAR strings throughout. I'd like to get rid of the TCHAR and use a C++ string instead. Is it still necessary to use the Windows wide functions, or can I do everything now with Unicode and UTF-8? Windows uses UTF16 still and most likely always will. You need to use wstring rather than string therefore. Windows APIs don't offer support for UTF8 directly largely because Windows supported Unicode before UTF8 was invented. It is thus rather painful

Why could i get an Unhandled exception Access violation writing in c++/CLI?

微笑、不失礼 提交于 2019-12-04 15:31:42
I have been struggeling writing a solution excisting out of an c++ win32console and a c++ dll. i finally managed to get them talking without linker errors (so i am assuming both are fully managed c++/CLI projects) but when i run the console i get the following error. Unhandled exception at 0x03f71849 in Company.Pins.Bank.Win32Console.exe: 0xC0000005: Access violation writing location 0x00000001. The console also shows the following Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at wmain in c:...\win32console.cpp:line 20 at