I am quite stumped on something in C. I found this code on the Internet, and it only gives me one error; however, I cannot seem to fix it. The variable in the function the compiler's complaining about is:

char ConvertTime[8]

and the function itself is a windows one:

GetWindowTextW(GETITEM(IDC_CONVERT_TIME), ConvertTime, 9);

Apparently it has something to do with LPWSTR. I'm not experienced in this realm, so I am asking nicely for help. Thanks in advance for any reply.

7 Years
Discussion Span
Last Post by ben25x

The function you are calling is UNICODE function. LPWSTR is a pointer to a unicode string, not an ascii string. You need to declare the string like this: wchar_t ConvertTime[9]; , or if you want to compile the program as either ascii or unicode then use the macro TCHAR: TCHAR ConvertTime[9]; and include <tchar.h> header file.


the thing about that is, later on down the road, there's a strncpy() function that doesn't like either method.

Edited by ben25x: messup on function name


tchar.h contains macros that can be used to treat standard c functions as either ascii or unicode, depending on how the program is written. If you replace strncpy() with _tscncpy() it will compile correctly either way. Read that article carefully and it will explain why, and give you an example. There are links at the bottom to other string manipulation functions.


I did everything recommended plus some but one other function that I have no idea what it is that it's complaining about:


Edited by ben25x: n/a


very funny. i need a tchar.h substitute for it. I know what it is.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.