MASM dll memory allocation

ε祈祈猫儿з 提交于 2019-12-11 06:38:54

问题


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:


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.



来源:https://stackoverflow.com/questions/27911123/masm-dll-memory-allocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!