www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to convert a LPCWSTR aka const(wchar)* to string

reply Vinod K Chandran <kcvinu82 gmail.com> writes:
Hi all.
I want to convert an LPCWSTR to string.
I have a struct like this
```cpp
typedef struct tagNMDATETIMESTRINGW {
   NMHDR      nmhdr;
   LPCWSTR    pszUserString;
   SYSTEMTIME st;
   DWORD      dwFlags;
} NMDATETIMESTRINGW, *LPNMDATETIMESTRINGW;
```
I want to convert this `pszUserString` to a string. How to do it. 
Thanks in advance.
May 09 2022
parent reply Mike Parker <aldacron gmail.com> writes:
On Tuesday, 10 May 2022 at 00:50:09 UTC, Vinod K Chandran wrote:

 I want to convert this `pszUserString` to a string. How to do 
 it. Thanks in advance.
```d import std.conv : to; string s = to!string(pszUserString); ```
May 09 2022
parent Vinod K Chandran <kcvinu82 gmail.com> writes:
On Tuesday, 10 May 2022 at 01:07:37 UTC, Mike Parker wrote:
 ```d
 import std.conv : to;
 string s = to!string(pszUserString);
 ```
Thanks, it worked. At first, I tried `to!string` but it failed because of this usage-- ```d this(LPCWSTR dtpStr) { this.dateString = to!string(LPCWSTR)(dtpStr) ; } ```
May 09 2022