• Welcome to Valhalla Legends Archive.
 

Winsock Wrapper

Started by iago, September 21, 2003, 09:44 PM

Previous topic - Next topic

Kp

Arta's code, as written, returns the message in an allocated buffer (either FormatMessage uses LocalAlloc or Arta invokes it manually if FormatMessage fails); in either case, the storage will need to be freed using LocalFree once the returned string is no longer in use.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

iago

What's the difference between LocalAlloc() and malloc()?  By the names, I would assume that LocalAlloc() does it on the function's stack, but since it has to be freed I doubt that's the case.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Kp

malloc is implemented as an attempt to be libc compatible.  LocalAlloc dates back to Win16 days, when you could allocate either local or global memory.  Incidentally, if you check the LocalAlloc documentation, it tells you that this is for Win16 only and you should not use it in Win32; thus, I find it odd FormatMessage uses it, since afaik FormatMessage is new enough it was created after LocalAlloc ought to have been deprecated.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

Adron

Presumably laziness wins in the long run. LocalAlloc has rather few arguments and so is easier to use.

Skywing

Quote from: Adron on October 10, 2003, 07:28 PM
Presumably laziness wins in the long run. LocalAlloc has rather few arguments and so is easier to use.
Last time I checked, malloc had fewer arguments... :p

Adron

Quote from: Skywing on October 10, 2003, 08:39 PM
Quote from: Adron on October 10, 2003, 07:28 PM
Presumably laziness wins in the long run. LocalAlloc has rather few arguments and so is easier to use.
Last time I checked, malloc had fewer arguments... :p

But malloc belongs to the C run-time library and so cannot be used by a kernel32(?) function. Well, that is, if you're using the malloc that has its own small block heap. If you're using the malloc that maps directly to the same heap that LocalAlloc uses they're of course interchangeable.