Re: SysFreeString - Is the memory mine to use as I please ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You can still use those with Win32 (and even Win64), but they are not the
best way to go for new code. I would recommend HeapAlloc(GetProcessHeap(),
....) and HeapFree(GetProcessHeap(), ...). The Global/Local functions, in
the Win32 age, are mostly just an extra layer of overhead over the standard
heap that provide services that most modern programs have no use for.

As far as conversions go, WideCharToMultiByte should be what you were
looking for.

The main differences between SysAllocString and SysFreeString are as
follows:

1. You are providing a standard allocator/deallocator pair for use with
OLE/COM, so that any time someone returns a string to you, you know how to
release it.
2. The allocator used with Sys*String is specially tuned for rapid
allocations and deallocations of character strings. There is some special
caching/pooling logic used that the normal, general-purpose heap allocator
does not employ.

--
Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net

"R.Wieser" <address@xxxxxxxxxxxxx> wrote in message
news:u7qkGvQ$GHA.4428@xxxxxxxxxxxxxxxxxxxxxxx
anton bassov <soviet_bloke@xxxxxxxxxxx> schreef in berichtnieuws
1162301218.742993.178710@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi mate

Hello to you too.

1) Am I allowed to do the Wide-char to ASCII conversion in-place ?

You can , but this is not as simple as just a type cast - there are
system-provided functions for this purpose,

? The one I found was "WideCharToMultiByte", a function of Kernel32.DLL.

and they do the conversion
for a particular type of wide string. For example, BSTR,
null-terminated string of wide characters and UNICODE_STRING are all
different types of wide-character string, so that they require
different conversion functions

:-) I'm afraid you're assuming I'm using C(++) or something in that
direction. I'm not. My current language-of-choice is Assembly.

2) How is SysFreeMemory different from Local/GlobalFree.

Local/GlobalFree are provided only for compatibility with 16-bit
Windows - there is no such thing as local/global memory under NT-based
system.

? I found Global/LocalAlloc (which are, according to the documentation,
two
names for the same function) in Kernel32. Its "clean up" actions
(Global/LocalFree) where there too. I'm using them with 32-bit Windows
programming.

If I might ask, What function are you using instead of them ?

SysFreeString()
simply deallocates memory for the string that has been dynamically
allocated by SysAllocString(). Therefore, your can think of them in
terms of malloc() - free() pair

Global/LocalFree is allso there for the purpose to release allocated
memory,
which made me wonder (if they could be used interchangably). If anything
I'm currently *more* confused, instead of less. :-\

Regards,
Rudy Wieser





.



Relevant Pages