Questions tagged [lpcstr]

Use this tag for questions related to the LPCSTR data type.

LPCSTR is a common data type used in Windows programming for representing strings. Its name is an acronym that stands for Long Pointer to Const String. From the corresponding MSDN page:

An LPCSTR is a 32-bit pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.

This type is declared as follows:

typedef const char* LPCSTR;
56 questions
0
votes
0 answers

Win32 API - error: assigning to 'LPCSTR' from incompatible type 'const wchar_t[]'

I have the following code, #include LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // Register the…
anathrax
  • 91
  • 1
  • 1
  • 11
0
votes
1 answer

LPCSTR data type conversion in problem in c++

I got some JSON value from swagger. I need to convert those values in my function accepted formate. mt4 function: JournalRequest(const int mode,const __time32_t from,const __time32_t to,LPCSTR filter,int *total) for converting date I just typecast…
0
votes
1 answer

Wrong value for LPCTSTR variable (?)

I have this method on a C++ project long CPPProject::CPPMethod(long lValue, LPCTSTR Data){ do something... } But, when I consume the method via a C# project, sometimes the value of Data is '?' For example: C# code: String sText1 = "u0110…
Ferrus
  • 15
  • 6
0
votes
2 answers

Why do I get "argument of type "LPCSTR" is incompatible with parameter of type "LPCWSTR" error when code compiles fine?

I am working on the following function: int initSerialPort(HANDLE* hSerialPort, LPCSTR portName){ *hSerialPort = CreateFile( portName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, …
user16541120
0
votes
1 answer

Converting LPCSTR to LPCWSTR in C++, ATL not available

Before I start, Please do understand that this question is not a duplicate. There are questions out there with the same header : Convert LPCSTR to LPCWSTR However, I did some research before asking this question and came across ATL or Active…
0
votes
1 answer

Redirection of a std::list content to a text file

I am using that code to enumerate files with specific extensions in a drive and write them out to a text file. It outputs something like this in the text file. How can I write file address with their names instead of these garbage…
Lilly kay
  • 3
  • 2
0
votes
1 answer

String literals to PTCHAR is deprecated

I am working on Legacy code where a string literal is assigned to a variable of type PTCHAR (pointer to char) which is defined in the header: typedef WCHAR TCHAR, *PTCHAR; PTCHAR str; str = _tcsrchr(dir, '\\'); *(str++)=0; str = TEXT("This is…
User1714
  • 37
  • 1
  • 6
0
votes
0 answers

LPCSTR to LPCWSTR converting

I have created implemetation of converting LPCSTR to LPCWSTR LPSTR W2S(LPCWSTR str) { LPSTR strTo; char* szTo = (char*)HeapAlloc(GetProcessHeap(), 0, lstrlenW(str) + 1); szTo[lstrlenW(str)] = '\0'; WideCharToMultiByte(CP_ACP, 0, str,…
korozya
  • 17
  • 6
0
votes
1 answer

Conversion from size_t to DWORD, possible loss of data

I'm building a 64bit C++ code on VS 2015. DWORD testVar; testVar= strLen((LPCSTR)src); // where src is a CString. Seeing Warning - C4267 'argument': conversion from 'size_t' to 'DWORD', possible loss of data. Any suggestions will be helpful.
user2769790
  • 123
  • 1
  • 17
0
votes
4 answers

'MessageBoxA' : cannot convert parameter 2 from 'std::vector<_Ty>' to 'LPCSTR'

The following code works: void CMyPlugin8::myMessageBox(std::string& myString) { myString = "Received the following string\n" + myString; char * writable = new char[myString.size() + 1]; std::copy(myString.begin(), myString.end(),…
Mickey D
  • 347
  • 2
  • 12
0
votes
2 answers

The value of lpcstr was corrupt when push it on Vector or List

first of all excuse me for my bad English. I have a function that generate a list of LPCSTR values, and i want to add all each of them to a list or vector , this is my sample code : vector output={}; // or…
Robert
  • 13
  • 1
0
votes
1 answer

LPCSTR- How to check if first Position is a Space " "

Simple Question. How to check what char is on first Position on a LPCSTR? Or just check if there is a Space on first Position?
Jens Krüger
  • 263
  • 1
  • 3
  • 18
0
votes
1 answer

How to efficiently replace characters within a string, which may repeat

I'm writing a string formatting function in LPC (...), but am versed in Javascript so a solution in either would be fine, the problem I am having is taking the following string for example: ~~~abc~~de~~~~~~~~~~~fgh~ And wrapping each ~ in a set of…
danjah
  • 2,939
  • 2
  • 30
  • 47
0
votes
4 answers

How to retrieve the specific element from an array of std::strings as a LPCSTR?

In C++, I've got a string array variable called: ... /* set the variable */ string fileRows[500]; ... /* fill the array with a file rows */ while ( getline(infile,sIn ) ) { fileRows[i] = sIn; i++; } and an object which has this: string…
szuniverse
  • 1,076
  • 4
  • 17
  • 32
0
votes
1 answer

C++ chars stored in the LPCSTR .. broken?

LPCSTR dllPath = ExePath().append("\\").append(DEF_INJECT_DLL).c_str(); DWORD dwBufSize = (DWORD)(strlen(dllPath) + 1) * sizeof(LPCSTR); /* test */ char tbuf[1024]= {0,}; sprintf_s(tbuf, "dllPath : %s\r\ndwBufSize : %d", dllPath,…