Ive been poking around with some win32 memory API's (GlobalAlloc, GlobalLock, etc)
and ive come across a annoying little problem!

Ok, heres the problem. I create a memory object (allocate memory) using the GlobalAlloc API.
Now i lock this memory with the GlobalLock API and it returns a pointer to the memory object.
I store this pointer in a dword variable named 'pMem'.

Now, im new to assembly, but i assume the pointer pMem contains a address to the first byte
of the memory object, however the thing is that i cannot for example do this:
(assuming the memory object contains some sort of data)

mov byte ptr, 30
or this..
cmp byte ptr, 30

(Note that i can do a movsb routine to move memory from pMem to a variable and it works fine.)

For all i know 'byte ptr' should point to the first byte in the memory object, but i must have
missed something!

Im thankful for any answers.
Posted on 2004-01-22 11:49:04 by kn9sk
Nope, in masm == pmem (ambiguous syntax), and equals the memory pointer, not the first byte it points to.

Since x86 doesn't have support for double indirection, you must first move this variable to a register... so:



mov eax, [pmem]
mov byte ptr [eax+30], 10

et cetera.

Btw, stay away from GlobalAlloc and friends unless you must use it (clipboard API), and use HeapAlloc and friends instead.
Posted on 2004-01-22 12:33:19 by f0dder
Thanks for the solution and thanks for the advice :)
Posted on 2004-01-22 12:44:28 by kn9sk
no problem, hope you get your stuff working. :alright:
Posted on 2004-01-22 12:47:24 by f0dder