MASM dll memory allocation

810 views Asked by At

I need help with my MASM dll. I'm counting elements in array then I want to allocate memory for another array, in C I'm using vector. I tried to use:

invoe GetProcessHeap
invoke HeapAlloc, eax, HEAP_NO_SERIALIZE + HEAP_ZERO_MEMORY, <size>

or

invoke GlobalAlloc, GMEM_ZEROINIT, <size>
mov tab, eax

but I'm getting errors undefined symbol : GetProcessHeap undefined symbol : HeapAlloc

I'm using this library in C# application. Can you show me example how can I dynamically allocate memory?

1

There are 1 answers

0
Michael On BEST ANSWER

You need to link against the appropriate library. If you look at the MSDN page for HeapAlloc you'll see that it's located in kernel32.dll.

Assuming that you're using MASM32 there should be a kernel32.inc (for the procedure prototype) and kernel32.lib (for linking) included with your MASM32 installation. So you need to add the following lines to your assembly file:

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

If you don't have a kernel32.lib file it gets a bit more complicated, but it's still doable by using LoadLibrary to load kernel32.dll and then getting the address of the HeapAlloc function with GetProcAddress.