The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Rainstorm on April 01, 2009, 10:37:20 PM

Title: Unicode & TCHAR
Post by: Rainstorm on April 01, 2009, 10:37:20 PM
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
Title: Re: Unicode & TCHAR
Post by: donkey on April 02, 2009, 12:08:35 AM
TCHAR is text character, it is 1 byte for ansi and 2 bytes for unicode, 1000 TCHARs is 2000 bytes.
Title: Re: Unicode & TCHAR
Post by: Rainstorm on April 02, 2009, 07:02:03 AM
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



Title: Re: Unicode & TCHAR
Post by: donkey on April 02, 2009, 07:48:34 AM
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
Title: Re: Unicode & TCHAR
Post by: KeepingRealBusy on April 02, 2009, 06:48:52 PM
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.
Title: Re: Unicode & TCHAR
Post by: Rainstorm on April 03, 2009, 12:28:59 PM
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