Pointer to wchar_t string to String?

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Pointer to wchar_t string to String?

Post by PaulDaMacMan » Tue Mar 16, 2021 8:42 pm

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).
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

liveme
Posts: 240
Joined: Thu Aug 27, 2015 5:22 pm
Location: down under

Re: Pointer to wchar_t string to String?

Post by liveme » Wed Mar 17, 2021 3:47 am

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

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Pointer to wchar_t string to String?

Post by PaulDaMacMan » Wed Mar 17, 2021 4:28 pm

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
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “LiveCode Builder”