Re: Shell Alloc and UNICODE
- From: "Mihai N." <nmihai_year_2000@xxxxxxxxx>
- Date: Sat, 06 Aug 2005 01:39:07 -0700
=?Utf-8?B?QWxl?= <Ale@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in news:E1489214-2EF7-
4B4D-89DD-4173779384B8@xxxxxxxxxxxxx:
> While there are memset/wmemset memcpy/wmemcpy, is there a function to
> allocate memory while using UNICODE!?
All memory allocation uses byte counts, by definition.
So there is nothing special about the UNICODE part. If you want to alloc
memory for an array of structs, you multiply the size of the array with
sizeof the struct. Same with Unicode, just multiply with sizeof(WCHAR).
> I've defined this macro:
> #define ShellAlloc(cb) (SHAlloc(cb*sizeof(TCHAR)))
Depends. If the string uses generic data types (TCHAR), then what you did is
ok. SHFileOperation uses generic string types, so probably this is also
what you need.
If the string is always Unicode (i.e. for COM operations), then you
have to use sizeof(WCHAR).
And I would try another name for the macro, something like: SHAllocString,
to make it clear is about strings. You can also do this to have it handy:
#define SHAllocString(cb) (SHAlloc(cb*sizeof(TCHAR)))
#define SHAllocStringW(cb) (SHAlloc(cb*sizeof(WCHAR)))
#define SHAllocStringA(cb) (SHAlloc(cb*sizeof(char)))
You can also alloc 1 more if you want not to take care of the NULL
explicitelly every single time you alloc something.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
.
- Follow-Ups:
- Re: Shell Alloc and UNICODE
- From: Ale
- Re: Shell Alloc and UNICODE
- References:
- Shell Alloc and UNICODE
- From: Ale
- Shell Alloc and UNICODE
- Prev by Date: property sheet
- Next by Date: Re: Shell Alloc and UNICODE
- Previous by thread: Shell Alloc and UNICODE
- Next by thread: Re: Shell Alloc and UNICODE
- Index(es):
Relevant Pages
|