Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#3245 closed Bug (Completed)

_MemVirtualAllocEx - pointer types

Reported by: francoiste Owned by:
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


in the Memory.Au3 include file:

for "_MemVirtualAlloc()" it should read:

Local $aResult = DllCall("kernel32.dll", "UINT", "VirtualAlloc", "UINT", $pAddress, "ulong_ptr", $iSize, "dword", $iAllocation, "dword", $iProtect)

for "_MemVirtualAllocEx()" it should read:

Local $aResult = DllCall("kernel32.dll", "UINT", "VirtualAllocEx", "handle", $hProcess, "UINT", $pAddress, "ulong_ptr", $iSize, "dword", $iAllocation, "dword", $iProtect)

Attachments (0)

Change History (5)

comment:1 Changed 3 years ago by francoiste

how to reproduce:

#include <Memory.au3>

Local $iAddress = _MemVirtualAlloc(0, 1024, $MEM_RESERVE + $MEM_TOP_DOWN, $PAGE_READWRITE)
ConsoleWrite("memory allocated at address: " & $iAddress & @CRLF)

additional info:
all memomory addresses need to be of type "unsigned".
in particular this is important for applications that are specially crafted to be "LargeAddressAware".

comment:2 Changed 3 years ago by Jpm

  • Resolution set to Completed
  • Status changed from new to closed
MsgBox(0, "_MemVirtualAlloc", "memory allocated at address: " & $iAddress & @CRLF & VarGetType($iAddress))

If you display the type you can see that there is no problem.
If you run in 64-Bit you get a large ptr

comment:3 Changed 3 years ago by francoiste

correction to the problem description:

at current the return types are incorrectly defined as "ptr".
but they actually are of type "uint_ptr" (i.e. unsigned).

but even if i fix it in my local "Memory.au3" include file it doesn't help:
either way the value is returned as HEX (e.g. "0xFFFA0000").
and i have not found any built-in method that converts it to decimal value by taking into consideration that it is an UNSIGNED integer!

however, i need the decimal representation for arithmetic comparison and some pointer logic.

so as workaround i'm currently doing:

  • call _MemVirtualAlloc()
  • convert the returned value to string
  • do some custom parsing of that hex value to calculate the decimal value myself

comment:4 Changed 3 years ago by francoiste

spawned a related discussion regarding unsigned integers:

comment:5 Changed 3 years ago by jchd18

Here again, you don't need the decimal value and even if you want it for display, my answer in the Help forum thread explains you how to do that reliably. There I also explain that you can do pointer arithmetic and comparison, provided you don't convert a pointer to an incompatible signed integer datatype, a pointless and error-prone operation.

An uint_ptr or whatever_type_ptr is a pointer, aka ptr.

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.