BBC BASIC for Windows
Programming >> Operating System >> Passing Unicode to edit control
http://bb4w.conforums.com/index.cgi?board=os&action=display&num=1315765792

Passing Unicode to edit control
Post by Nick on Sep 11th, 2011, 6:29pm

Hello again,

(I had typed this once and hit "Post" but it didn't get posted for some reason)

in brief: say I have some data in a buffer representing unicode text - let;s assign it to G%.

Then, two letter "M"s would look like this:

&4D &00 &4D &00

And I want to pass them to an edit control. I can NOT do it like this:

SYS "SetWindowText", hRichEdit%, $$G%

This is because BBC4W interprets the second byte (&00) as a sting terminator. All that gets passed to the control is a single letter "M"!

How do I 'assign' a buffer of such unicode text in such a way that I define the length of the 'string' to be passed rather than using the typical X$ type variable?

Thanks

Nick
Re: Passing Unicode to edit control
Post by admin on Sep 11th, 2011, 9:10pm

on Sep 11th, 2011, 6:29pm, Nick wrote:
How do I 'assign' a buffer of such unicode text in such a way that I define the length of the 'string' to be passed rather than using the typical X$ type variable?

The problem isn't that the string is held in a variable (like X$) since string variables can contain NULs (zero bytes) quite happily. Rather, it's because you are using the $$ operator, which assumes the first NUL terminates the string.

So one solution is not to use $$ at all, but simply to pass a regular string variable to the editor thus:

Code:
SYS "SetWindowTextW", hRichEdit%, X$ 

For this to work you must ensure that the variable X$ contains at least one terminating NUL at the end (since BASIC adds only one extra NUL, and UTF-16 requires a termination of two NULs).

Another approach would be to pass the address of a memory buffer containing the string (which would then need both terminating NULs to be explicitly stored):

Code:
SYS "SetWindowTextW", hRichEdit%, A% 

Richard.