convert SYSTEMTIME to LPCWSTR [duplicate] - c++

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Is there a function like asctime_s() that works for SYSTEMTIME structures in windows?
I need to convert a type of SYSTEMTIME to a string. Then append the string product onto another string. Then finally convert the final string to type of LPCWSTR
All of the properties of the SYSTEMTIME are WORD types.
I think I need to convert the WORD types to wchar_t types and then concatenate them to get the string of SYSTEMTIME. How do I do this conversion and concatenation?
Once the final string has been built how can a LPCWSTR type be made from it?

Use GetTimeFormatEx or GetTimeFormat if you need to support Windows XP to format a SYSTEM time to a string.

Related

Getting a path and appending a filename [duplicate]

This question already has answers here:
How do I concatenate two strings in C?
(12 answers)
How to concatenate two strings in C++?
(8 answers)
Closed 6 years ago.
I'm trying to get a path (appdata) and append a filename (smss.dll), and combine these two to form C:\users\username\appdata\roaming\smss.dll
I have this already:
static char appdata[MAX_PATH+1];
SHGetSpecialFolderPathA(HWND_DESKTOP, appdata, CSIDL_APPDATA, FALSE);
LPCSTR target = "smss.dll";
How can I combine these to into one variable?
You can use PathAppend (limited to MAX_PATH characters), or PathCchAppendEx starting with Windows 8.
static char appdata[MAX_PATH+1];
SHGetSpecialFolderPathA(HWND_DESKTOP, appdata, CSIDL_APPDATA, FALSE);
strcat(appdata, "\\smss.dll");
The strcat function appends the right-hand string to the left-hand buffer. It assumes the destination has room for the concatenation to be done. If there is not enough space, it is undefined behavior. Thus it is a good idea to check that there is enough space.

Is a C++ string class which I can use to process UTF8 strings? [duplicate]

This question already has answers here:
std::string and UTF-8 encoded unicode
(3 answers)
What encoding does std::string.c_str() use?
(2 answers)
Closed 8 years ago.
I think string can handle ANSI and wstring can handle Unicode16, is that right?
does C++ STL has class which can support UTF8 strings?
Just use std::string. It handles UTF-8 strings just fine.
Obviously you need to be aware that a codepoint can be 1 to 4 chars, and that a character can actually be any number of codepoints, but that rarely matters to you, and when it matters, std::wstring would have the same problems.
Big advantage is that std::string works the same everywhere. With std::wstring, different implementations use 16 bit or 32 bit numbers with very different meanings, there are problems with byte ordering and so on.

What does this string in c++ mean? [duplicate]

This question already has answers here:
What does the 'L' in front a string mean in C++?
(7 answers)
Closed 8 years ago.
LPWSTR l = L"D:/MyFile.txt";
I've searched everywhere, but couldnt find the answer. Thank you!
Long Pointer to Wide Character String. And you didn't search everywhere cause 1st google hit on LPWSTR points to MSDN:
The LPWSTR type is a 32-bit pointer to a string of 16-bit Unicode characters, which MAY be null-terminated. The LPWSTR type specifies a pointer to a sequence of Unicode characters, which MAY be terminated by a null character (usually referred to as "null-terminated Unicode").
typedef wchar_t* LPWSTR, *PWSTR;
And L in front of the literal specifies how the literal should be understood. It's kind of like suffixes for numeric types e.g: 10u, 4.0f. Because type is W (wchar_t), the appropriate counterpart for a literal definition is L.

Meaning of L near text in define [duplicate]

This question already has answers here:
What exactly is the L prefix in C++?
(3 answers)
Why is letter L used to indicate wide chars strings?
(2 answers)
Closed 8 years ago.
I came across something I can't search for what it means.
#define DEFAULT_KEY L"text"
What does 'L' mean or do?
Other example that I found
wcscat(xpath, L"\\");
It means the string literal has type const wchar_t*, which is a type different that const char*. It is usually used to store Unicode strings.
Some APIs (particularly the Windows API) use this type all over the place.
The L prefix denotes a wide character/string literal; i.e., it is of type wchar_t instead of char. Unicode based programs typically use wide strings, while ANSI/ASCII based programs typically do not.

C win32 api unicode to ascii [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you convert LPCWSTR to const char *?
I have a function that gets a LPCWSTR string for win32 api usage.
Now I have a function that sends data in ASCII to the IRC server.
So now I need to convert it to ASCII, I haven't found any solutions, I only found ways to convert ASCII to UNICODE.
WideCharToMultiByte converts from UNICODE to MBCS. If your original wide char string consisted only of characters which could be represented in ASCII, then this will result in a ASCII string.
You can also use wcstombs which internally calls WideCharToMultiByte.
Either way, you will get a LPSTR or char * (which are the same).