Do anyone know some things about HeapAlloc, GlobalAlloc, LocalAlloc and Virtual Protect.

1:
I have to call GlobalAlloc or LocalAlloc six separate times before one of my procedure is completed. Do I have to call GlobalFree or LocalFree every time or can i do it at the end of the procedure only once. And also which one of these api's is only visible with-in your own process and work for all Windows versions. I am also wondering how to use StrLen and a Large Buffer to do it... I think we all would really love that (another api in the M32.lib). . . .Any idea would we greatly appreciated.

2:
I got a three main Procedure that i want to keep near ToTally private and not be seen outside my process when theses Procedures is running under Windows. So I been reading a little about Virtual Protect but the way it seem there is all kind of information about how to Un-Protect someone's app instead of Protecting your own app from intruder . . .

Is there some serious information about these api's anywhere. And could someone give me an idea of how to use Virtual Protect for protecting a Procedure or even an entire app if possible and what do it Really Protect....Posted on 2002-03-29 09:09:15 by cmax
for every new call to alloc memory you need to close that memory or you will have a memory leak. use for global allocation:

GlobalUnlock
GlobalFree
Posted on 2002-03-29 09:24:13 by smurf
Welcome back smurf

It seem like you been gone for a while. Thanks for the reply. I did a search on GlobalUnlock and got some good info about it. No matter how long you do this stuff you find yourself back to Iczelion's tutorials just because you were not interested in the subject than...Now I Am... That was great for starters...

Thanks Again
Posted on 2002-03-29 10:03:20 by cmax
cmax, globalalloc=localalloc, and they both map to heapalloc after
some flag conversions. HeapAlloc allows you to work with multiple
heaps - this also means you can dealloc all allocated memory in a
heap at once, with HeapDestroy. So if you have "an impressive"
amount of allocs, it might be faster to create a new heap and use
heapcreate/heapalloc(s)/heapdestroy.

As for documentation on the APIs, platformsdk... platformsdk... :)

The VirtualProtect is not protect as in "keep intruders out", it's
just for utilizing the page-level protection mechanism of the IA32.
Better not mess with this unless you know what you're doing, it can
cause more trouble than it fixes.
Posted on 2002-03-29 18:05:24 by f0dder
"HeapAlloc" may be best. I will read a lot more about it. Thanks for setting me stright about VP.

There is one last thing i need to learn how to do if possible. If you sometimes know the amount of byte that will be used can you and how would you set it up so that it work or think like Alloc. I tried difference ways but never founded a way to do anything with it. And what do you thnk about or is it possible to rig something up using Memfill, Memcopy, Ernie's pIMalloc Funtion in the M32.lib...


invoke GlobalAlloc, GHND, nLen
mov hMem, eax
bla.....
bla.....
invoke GlobalFree, hMem

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Buffer1 DB 1024 (DUP)

Fill My Buffer

Posted on 2002-03-29 21:53:48 by cmax
cmax,

Yep I guess HeapAlloc is best... but I still use GlobalAlloc from time to time... I use them with these macros...



add to your .data? :

hMemory DWORD ?
pMemory DWORD ?

and put up those two macros:

AllocMem MACRO howbig
invoke GlobalAlloc,GHND,howbig
mov hMemory,eax
invoke GlobalLock,eax
mov pMemory,eax
ENDM

DeAllocMem MACRO
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
mov hMemory,0
ENDM


Use them like this:



AllocMem 1024 ;returns in eax and pMemory the pointer to the Buffer
invoke ReadFile,hFile,eax,1024,ADDR dummy,NULL
DeAllocMem


That's it.. saves typing.. (and btw... you can modify them by your needs for HeapAlloc etc...) I'm just lazy as hell and put lots of stuff in either invokable or macro form.
Posted on 2002-03-29 22:08:21 by JimmyClif