copy LPSTR to LPWSTR
-
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data. Thank you.
Saadhinchaali
-
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data. Thank you.
Saadhinchaali
Saadhinchaali wrote:
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data.
You sure about that? Such an attempt will cause a compiler error.
LPCSTR pChar = "LPCSTR";
LPCWSTR pWChar = L"LPCWSTR";
pWChar = pChar; // error C2440: '=' : cannot convert from 'const char *' to 'const unsigned short *'Even if that made sense, which it doesn't, it would only copy the pointers. Don't tell me you cast the problem away! Show us some code.
Steve
-
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data. Thank you.
Saadhinchaali
Saadhinchaali wrote:
How can i copy a string (LPSTR) to a wide string variable (LPWSTR).
They are quite different beasts, do you need to convert. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Saadhinchaali wrote:
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data.
You sure about that? Such an attempt will cause a compiler error.
LPCSTR pChar = "LPCSTR";
LPCWSTR pWChar = L"LPCWSTR";
pWChar = pChar; // error C2440: '=' : cannot convert from 'const char *' to 'const unsigned short *'Even if that made sense, which it doesn't, it would only copy the pointers. Don't tell me you cast the problem away! Show us some code.
Steve
Stephen Hewitt wrote:
LPCSTR pChar = "LPCSTR"; LPCWSTR pWChar = L"LPCWSTR"; pWChar = pChar; // error C2440: '=' : cannot convert from 'const char *' to 'const unsigned short *'
sorry. I casted the problem away
LPCWSTR pWChar = (LPWSTR) pChar
Saadhinchaali
-
Stephen Hewitt wrote:
LPCSTR pChar = "LPCSTR"; LPCWSTR pWChar = L"LPCWSTR"; pWChar = pChar; // error C2440: '=' : cannot convert from 'const char *' to 'const unsigned short *'
sorry. I casted the problem away
LPCWSTR pWChar = (LPWSTR) pChar
Saadhinchaali
Saadhinchaali wrote:
sorry. I casted the problem away
Don't! The compiler issues an error for a reason! Calling a dog a cat doesn't make it one!
Steve
-
Saadhinchaali wrote:
sorry. I casted the problem away
Don't! The compiler issues an error for a reason! Calling a dog a cat doesn't make it one!
Steve
Actually the compiler is happy about it (I suspect it enjoys such mistakes...). :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data. Thank you.
Saadhinchaali
I suggest you try to understand the concepts that are behind by reading this series of articles[^]. At least, you will understand why you can't cast the pointers directly.
Cédric Moonen Software developer
Charting control [v1.4 - Updated] -
How can i copy a string (LPSTR) to a wide string variable (LPWSTR). When i am assigning directly (=) i am loosing some data. Thank you.
Saadhinchaali
Hi, U cannot directly cast a LPSTR to Widechar LPWSTR and if u do that u will lose data. use API MultiByteToWideChar to do it. thanks Nitheesh
-
Hi, U cannot directly cast a LPSTR to Widechar LPWSTR and if u do that u will lose data. use API MultiByteToWideChar to do it. thanks Nitheesh
Actually you don't loose any data. Anyway your conclusion is correct: there must be a
conversion
to get a corrensponding string as result. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Saadhinchaali wrote:
sorry. I casted the problem away
Don't! The compiler issues an error for a reason! Calling a dog a cat doesn't make it one!
Steve
Stephen Hewitt wrote:
Calling a dog a cat doesn't make it one!
Too funny!
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne