lpcstr

Appending BSTR in a LPCSTR

坚强是说给别人听的谎言 提交于 2019-12-12 12:27:03
问题 I have a class function which is receving a BSTR. In my class I have a member variable which is LPCSTR. Now I need to append BSTR ins LPCSTR. How I can do that. Here is my function. void MyClass::MyFunction(BSTR text) { LPCSTR name = "Name: "; m_classMember = name + text; // m_classMember is LPCSTR. } in my m_classMember I want that after this function value should be "Name: text_received_in_function". How i can do that. 回答1: Use the Microsoft specific _bstr_t class, which handles the ANSI

Weird behavior while converting a std::string to a LPCSTR

我的未来我决定 提交于 2019-12-12 04:19:47
问题 I was playing with some strings when I stumbled upon a weird behavior while converting a std::string to a LPCSTR . I have written a small test application to demonstrate : #include <string> #include <Windows.h> #include <iostream> using namespace std; int main () { string stringTest = (string("some text") + " in addition with this other text").c_str(); LPCSTR lpstrTest= stringTest.c_str(); cout << lpcstrTest << '\n'; cout << (string("some text") + " in addition with this other text").c_str()

C++ CLI System.String^ to MFC LPCTSTR

半世苍凉 提交于 2019-12-09 09:41:12
问题 How would I convert a System (.net) C++\CLI String^ into a MFC C++ LPCTSTR string. It is very easy to get a LPCTSTR into String^ , but so far found nothing on doing it the other way around. 回答1: If you have Visual Studio 2008 or above, you should be able to do this using the C++/CLI marshaling library, like so: #include <msclr\marshal.h> using namespace System; using namespace msclr::interop; ... String^ cliString; marshal_context context; LPCTSTR cstr = context.marshal_as<const TCHAR*>

How to convert QString to LPCSTR (Unicode)

扶醉桌前 提交于 2019-12-08 02:34:07
问题 how can I convert QString to LPCSTR ? How do I do it when #ifdef UNICODE is defined and when it isn't ? Thanks very much :) 回答1: I guess: QString str("ddddd"); LPCSTR lstr = str.toStdString().c_str(); 回答2: QString can always hold Unicode; LPCSTR is never Unicode. This means that you do have to consider what to do with the characters that won't fit. This isn't a "which method to use" question, but a design question. It's quite possible that in your specific case, you absolutely know that the

How to convert QString to LPCSTR (Unicode)

我的未来我决定 提交于 2019-12-06 07:47:14
how can I convert QString to LPCSTR ? How do I do it when #ifdef UNICODE is defined and when it isn't ? Thanks very much :) I guess: QString str("ddddd"); LPCSTR lstr = str.toStdString().c_str(); QString can always hold Unicode; LPCSTR is never Unicode. This means that you do have to consider what to do with the characters that won't fit. This isn't a "which method to use" question, but a design question. It's quite possible that in your specific case, you absolutely know that the QString only contaisn characters from your local "ANSI" codepage (also known as ACP ). In that case, the correct

C++ CLI System.String^ to MFC LPCTSTR

本小妞迷上赌 提交于 2019-12-03 12:33:42
How would I convert a System (.net) C++\CLI String^ into a MFC C++ LPCTSTR string. It is very easy to get a LPCTSTR into String^ , but so far found nothing on doing it the other way around. If you have Visual Studio 2008 or above, you should be able to do this using the C++/CLI marshaling library, like so: #include <msclr\marshal.h> using namespace System; using namespace msclr::interop; ... String^ cliString; marshal_context context; LPCTSTR cstr = context.marshal_as<const TCHAR*>(cliString); More information on marshaling between types on MSDN: Overview of Marshaling in C++ You might want to

C++ LPCTSTR to char*

本小妞迷上赌 提交于 2019-12-02 09:18:55
I am using visual studio 2010 MFC to build a C++ program. My program calls a DLL that is not apart of the project and it accepts a char*. I have a function that gets a string in a format of LPCTSTR. I have been on google for about two hours now, and no solution found. How do I convert form a MFC LPCTSTR to a char*. Everything I have found either does not work, or just does not compile. Roman R. In MFC the easiest is to convert through CStringA (provided that resulting buffer will be a read-only argument): LPCTSTR pszA = ... CStringA sB(pszA); const char* pszC = sB; char* pszD = const_cast<char

how can convert LPCSTR string into LPCTSTR string?

懵懂的女人 提交于 2019-12-02 04:57:13
问题 i am trying to convert a LPCSTR string into LPCTSTR string. i want to concatenate two string,when i try like this LPCTSTR str1 = L"Raja" LPCSTR str2 = "Kumar" wcscat_s(str1,(LPCTSTR)str2); i found the o/p like Raja....r(junkvalues)....how can typecast LPCSTR to LPCTSTR ? 回答1: LPCTSTR can be either plain char or wide characters depending on your project settings. Further, you cannot possibly concatenate a wide string and a plain char string. You need to convert one to a compatible form (wide

how can convert LPCSTR string into LPCTSTR string?

試著忘記壹切 提交于 2019-12-02 02:40:10
i am trying to convert a LPCSTR string into LPCTSTR string. i want to concatenate two string,when i try like this LPCTSTR str1 = L"Raja" LPCSTR str2 = "Kumar" wcscat_s(str1,(LPCTSTR)str2); i found the o/p like Raja....r(junkvalues)....how can typecast LPCSTR to LPCTSTR ? LPCTSTR can be either plain char or wide characters depending on your project settings. Further, you cannot possibly concatenate a wide string and a plain char string. You need to convert one to a compatible form (wide to multibyte or vice versa) and then concatenate. Assuming you want the target to be a wide string, you'd

What does LPCWSTR stand for and how should it be handled with?

假装没事ソ 提交于 2019-11-26 12:38:23
问题 First of all, what is it exactly? I guess it is a pointer (LPC means long pointer constant), but what does \"W\" mean? Is it a specific pointer to a string or a pointer to a specific string? For example I want to close a Window named \"TestWindow\". HWND g_hTest; LPCWSTR a; *a = (\"TestWindow\"); g_hTest = FindWindowEx(NULL, NULL, NULL, a); DestroyWindow(g_hTest); The code is illegal and it doesn\'t work since const char[6] cannot be converted to CONST WCHAR. I don\'t get it at all. I want to