Page 1 of 1

Pointer to wchar_t string to String?

Posted: Tue Mar 16, 2021 8:42 pm
by PaulDaMacMan
Pretty much what the topic asks.
I have a struct that contains 3 elements that are Pointers that point to wchar_t strings (there's also another element that's a pointer to a C string which is not a problem at all) and I'm having a hell of a time trying to retrieve them and/or convert them to a regular LCB String type. I worked out a hack to do it on macOS that seems to work quite well, but it's a total fail on Windows. I've tried tapping into various <builtin> functions found in Livecode's foundation.h header with not much success. In fact, I seem to be getting further from a solution. It's very frustrating because these are just name strings, important for humans, but not actually important to the functionality of the library I'm wrapping (HIDAPI).

Re: Pointer to wchar_t string to String?

Posted: Wed Mar 17, 2021 3:47 am
by liveme
possibly pasting some...

Code: Select all

 Hell of a code here
would help you reach faster some

Code: Select all

Heavenly code here
..my 1 cents 1/2
:P

Re: Pointer to wchar_t string to String?

Posted: Wed Mar 17, 2021 4:28 pm
by PaulDaMacMan
OK, I think I figured out the problem tapping into this <builtin> function

Code: Select all

MCStringCreateWithWString(const unichar_t *wstring, MCStringRef& r_string);
Seems like this actually does work fine on Windows, but was crashing the engine on macOS?
I'm Not 100% sure, but now I have a split if the OS is windows it uses the above, else any other OS it uses my getWCharString (which is a bit hacky, and works by pulling ANSI characters out of the character array and looking for a bunch of nulls in a row for string termination). Bottom line is it's working on both macOS & Windows now.

Here is the LCB Code if anyone is interested: https://github.com/PaulMcClernan/LCB_HI ... HIDAPI.lcb