tchar

How to convert std::wstring to a TCHAR*

亡梦爱人 提交于 2019-12-04 10:28:27
std::wstring.c_str() returns a wchar_t*. How do I get from wchar_t* to TCHAR*, or from std::wstring to TCHAR* Thanks #include <atlconv.h> TCHAR *dst = W2T(src.c_str()); Will do the right thing in ANSI or Unicode builds. use this : wstring str1(L"Hello world"); TCHAR * v1 = (wchar_t *)str1.c_str(); 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; #else //I think W2A is defined in atlbase.h, and it returns a stack-allocated var. //If that's not OK, look at the

error C2446: == : no conversion from const char * to TCHAR *

喜你入骨 提交于 2019-12-04 04:50:16
问题 I have a TCHAR define below: TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); and I want to comapare as below: if(szProcessName == "NDSClient.exe") { } But then I am getting the errors: error C2446: == : no conversion from const char * to TCHAR * error C2440: '==' : cannot convert from 'const char [14]' to 'TCHAR [260]' 回答1: "NDSClient.exe" is a const char* string on windows. If you want it to become a const TCHAR* then you need to use the TEXT macro. Also, you can not compare strings using

How do you convert a 'System::String ^' to 'TCHAR'?

China☆狼群 提交于 2019-12-02 02:09:56
i asked a question here involving C++ and C# communicating. The problem got solved but led to a new problem. this returns a String (C#) return Marshal.PtrToStringAnsi(decryptsn(InpData)); this expects a TCHAR* (C++) lpAlpha2[0] = Company::Pins::Bank::Decryption::Decrypt::Decryption("123456"); i've googled how to solve this problem, but i am not sure why the String has a carrot(^) on it. Would it be best to change the return from String to something else that C++ would accept? or would i need to do a convert before assigning the value? That is a really rambling way to ask the question, but if

error C2446: == : no conversion from const char * to TCHAR *

a 夏天 提交于 2019-12-01 23:46:27
I have a TCHAR define below: TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); and I want to comapare as below: if(szProcessName == "NDSClient.exe") { } But then I am getting the errors: error C2446: == : no conversion from const char * to TCHAR * error C2440: '==' : cannot convert from 'const char [14]' to 'TCHAR [260]' "NDSClient.exe" is a const char* string on windows. If you want it to become a const TCHAR* then you need to use the TEXT macro. Also, you can not compare strings using == use a equivalent TCHAR function such as _tcscmp . Mihran Hovsepyan Also you can use. L"some string" to

cannot convert from 'const char *' to 'LPCTSTR'

半世苍凉 提交于 2019-12-01 14:52:48
I'm trying to convert string to 'LPCTSTR', but, i got following error. Error : cannot convert from 'const char *' to 'LPCTSTR' code: std::string str = "helloworld"; LPCTSTR lp = str.c_str(); Also, tried : LPCTSTR lp = (LPCTSTR)str.c_str(); But, print garbage value. Zebrafish LPCTSTR means (long pointer to constant TCHAR string). A TCHAR can either be wchar_t or char based on what your project settings are. If, in your project settings, in the "General" tab, your character set is "Use Multi-byte character set" then TCHAR is an alias for char . However, if it's set to "Use Unicode character set"

What are TCHAR strings and the 'A' or 'W' version of Win32 API functions? [duplicate]

拥有回忆 提交于 2019-12-01 10:37:41
This question already has an answer here: Strings. TCHAR LPWCS LPCTSTR CString. Whats what here, simple quick 2 answers What are TCHAR strings, such as LPTSTR and LPCTSTR and how can I work with these? When I create a new project in Visual Studio it creates this code for me: #include <tchar.h> int _tmain(int argc, _TCHAR* argv[]) { return 0; } How can I, for instance, concatenate all the command line arguments? If I'd want to open a file with the name given by the first command line argument, how can I do this? The Windows API defines 'A' and 'W' versions of many of its functions, such as

What are TCHAR strings and the 'A' or 'W' version of Win32 API functions? [duplicate]

天大地大妈咪最大 提交于 2019-12-01 08:35:39
问题 This question already has answers here : Strings. TCHAR LPWCS LPCTSTR CString. Whats what here, simple quick (2 answers) Closed 4 years ago . What are TCHAR strings, such as LPTSTR and LPCTSTR and how can I work with these? When I create a new project in Visual Studio it creates this code for me: #include <tchar.h> int _tmain(int argc, _TCHAR* argv[]) { return 0; } How can I, for instance, concatenate all the command line arguments? If I'd want to open a file with the name given by the first

How to convert char* to TCHAR[ ]? [duplicate]

爱⌒轻易说出口 提交于 2019-12-01 06:39:34
This question already has an answer here: Convert char to TCHAR* argv[] 2 answers char* stheParameterFileName = argv[1]; //I'm passing the file name as a parameter. TCHAR szName [512]; How can I convert char* to TCHAR [] ? If you include the header file: #include "atlstr.h" Then you can use the A2T macro as below: // You'd need this line if using earlier versions of ATL/Visual Studio // USES_CONVERSION; char* stheParameterFileName = argv[1]; TCHAR szName [512]; _tcscpy(szName, A2T(stheParameterFileName)); MessageBox(NULL, szName, szName, MB_OK); Details on MSDN Form MSDN : // convert_from_char

Converting _TCHAR* to char*

久未见 提交于 2019-12-01 05:45:29
I'm trying to get a simple OpenCV sample working in C++ on Windows and my C++ is more than rusty. The sample is fairly simple: #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace cv; using namespace std; int main( int argc, char** argv ) { if( argc != 2) { cout <<" Usage: display_image ImageToLoadAndDisplay" << endl; return -1; } Mat image; image = imread(argv[1], IMREAD_COLOR); // Read the file if(! image.data ) // Check for invalid input { cout << "Could not open or find the image" << std::endl ; return -1; } namedWindow( "Display

How do I convert from _TCHAR * to char * when using C++ variable-length args?

前提是你 提交于 2019-12-01 03:43:09
We need to pass a format _TCHAR * string, and a number of char * strings into a function with variable-length args: inline void FooBar(const _TCHAR *szFmt, const char *cArgs, ...) { //... } So it can be called like so: char *foo = "foo"; char *bar = "bar"; LogToFileA(_T("Test %s %s"), foo, bar); Obviously a simple fix would be to use _TCHAR instead of char, but we don't have that luxury unfortunately. We need to use this with va_start, etc so we can format a string: va_list args; _TCHAR szBuf[BUFFER_MED_SIZE]; va_start(args, cArgs); _vstprintf_s(szBuf, BUFFER_MED_SIZE, szFmt, args); va_end