BBC BASIC for Windows
« Passing Unicode to edit control »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:21pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Passing Unicode to edit control  (Read 805 times)
Nick
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 33
xx Passing Unicode to edit control
« Thread started 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Passing Unicode to edit control
« Reply #1 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls