News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Unicode & TCHAR

Started by Rainstorm, April 01, 2009, 10:37:20 PM

Previous topic - Next topic

Rainstorm

Hi,
when using Unicode functions, if i gotta specify for example 'the size of the string buffer in TCHARS', would this number be, half the size of the buffer in bytes ?
for example if the buffer was 4000 bytes, i'd have to supply the size in the call as 2000 ?

Also just realised there is no inherent way to declare .data strings in the unicode section ;p
-using the WSTR macro in the umacros.asm file for that currently

ty

donkey

TCHAR is text character, it is 1 byte for ansi and 2 bytes for unicode, 1000 TCHARs is 2000 bytes.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Rainstorm

thanks, i didn't realise the T there was for text till now : )

here's an example of its usage


    fname_buff       db  32000 dup (0)   ; buff for the filepath
. . .
code:
    invoke GetTempPathW, 16000, addr fname_buff
    fn MessageBoxW, 0, addr fname_buff, addr mtitle, MB_OK




donkey

32K in the data section is a bit much when the file path is unlikely to exceed MAX_PATH (260 TCHARs)  unless it uses the \\?\ and then it can be up to 32768 TCHARs which would overflow anyway. If you really want to use 32K as a buffer then think about allocating it dynamically..

.DATA?
pFileNameBuff DD ?
.CODE
invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,32000
mov [pFileNameBuff], eax

invoke GetTempPathW, 16000,  [pFileNameBuff]
invoke MessageBoxW, NULL, [pFileNameBuff], addr mtitle, MB_OK

; when you're done with it
invoke GetProcessHeap
invoke HeapFree, eax,  NULL, [pFileNameBuff]


Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

KeepingRealBusy

Donkey,

Why does everyone suggest HeapAllocate? I have seen this in several places. Wouldn't VirtualAlloc be more efficient, i.e., no overhead for the heap maintenance?

Dave.

Rainstorm

donkey wrote..
Quote32K in the data section is a bit much when the file path is unlikely to exceed MAX_PATH (260 TCHARs)
just realised,..so if its unicode for 260 TCHARS i'd have to allocate around  520 bytes & for 32,000 TCHARS my buffer would actually have to be 32,000 × 2 bytes.
Also the \\?\ prefix needs to be used in my code,.. right ? to prepend the path

t  y