flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > [SOLVED] SQLite + ListView [chars encoding problem]

Author
Thread Post new topic Reply to topic
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
[SOLVED] SQLite + ListView [chars encoding problem]
Hey there!

Need some help fixing this code snippet, for it is displaying wrong chars in listview.

Thanks,
ctl3d32


Description: source code + database files
Download
Filename: listview.zip
Filesize: 2.67 KB
Downloaded: 32 Time(s)



Last edited by ctl3d32 on 22 Jun 2017, 00:28; edited 1 time in total
Post 21 Jun 2017, 18:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15168
Location: GW170817
From what I can tell your basic problem is to convert from the UTF8 encoding stored in the DB into a 'wide' UCS2 encoding for Windows.

So you'll need three changes.

0. Instantiate a 'wide' version of the LVI structure.
1. Make a UTF8-to-wide converter function. Windows doesn't provide one by default but the code for it should be quite simple. Read each UTF8 character and do a bit of bit shifting to create the 2-byte 'wide' characters.
2. Call the wide version of SendMessage to insert the converted text.

Code:
invoke SendMessageW,[hListView],LVM_INSERTITEM,0,lviW

Post 21 Jun 2017, 19:17
View user's profile Send private message Visit poster's website Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
Thanks revolution. Gonna try that.
Post 21 Jun 2017, 21:36
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil

revolution wrote:
From what I can tell your basic problem is to convert from the UTF8 encoding stored in the DB into a 'wide' UCS2 encoding for Windows.

So you'll need three changes.

0. Instantiate a 'wide' version of the LVI structure.
1. Make a UTF8-to-wide converter function. Windows doesn't provide one by default but the code for it should be quite simple. Read each UTF8 character and do a bit of bit shifting to create the 2-byte 'wide' characters.
2. Call the wide version of SendMessage to insert the converted text.

Code:
invoke SendMessageW,[hListView],LVM_INSERTITEM,0,lviW




Actually, windows has a UTF8-to-wide and a wide-to-Multibyte converter. I used them and i got it working. No need to use SendMessageW.

Changes in the code are shown below:


Code:

        ;+++++++++++++++++++++++++++++++++++++++++++++++++

        invoke  RtlZeroMemory,szBuffer,MAX_PATH
        invoke  RtlZeroMemory,szBuffer2,MAX_PATH

        mov     dword[lvi + LV_ITEM.iItem],9999d
        cinvoke sqlite3_column_bytes,[hStmt],0
        mov     [ibytes],eax
        cinvoke sqlite3_column_text,[hStmt],0

        invoke  MultiByteToWideChar,CP_UTF8,0,eax,[ibytes],szBuffer,MAX_PATH
        invoke  WideCharToMultiByte,CP_ACP,0,szBuffer,[ibytes],szBuffer2,MAX_PATH,NULL,NULL

        lea     eax,[szBuffer2]
        mov     [lvi + LV_ITEM.pszText],eax
        invoke  SendMessage,[hListView],LVM_INSERTITEM,0,lvi
        jmp     @b

        ;+++++++++++++++++++++++++++++++++++++++++++++++++ 




Thanks


Description: Updated Source Code
Download
Filename: ListView_Example.ASM
Filesize: 6.82 KB
Downloaded: 31 Time(s)

Post 22 Jun 2017, 00:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15168
Location: GW170817

ctl3d32 wrote:
Actually, windows has a UTF8-to-wide and a wide-to-Multibyte converter. I used them and i got it working.

Okay, good to know.

ctl3d32 wrote:
No need to use SendMessageW.

Okay, if the current code page supports all the characters you are using. But you limit your total characters to 256. If a user wants to use Chinese or Korean or something then there might not be an equivalent character available within the 256 set in the current code page.
Post 22 Jun 2017, 07:57
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.