News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

displaying pointer value in messagebox problem

Started by pavellus, July 04, 2006, 04:24:56 PM

Previous topic - Next topic

pavellus

Hello I want to display a pointer value (f.e. handle to window) in MessageBox and this doesn't work.

showPointerValue proc handle:DWORD
  LOCAL memHandle :DWORD
  invoke GlobalAlloc, LMEM_FIXED, 20 ;return eax - handle to allocated 20 bytes
  mov memHandle, eax
  invoke dwtoa, memHandle, ADDR handle  ; dwtoa is a procedure stored in masm32/m32lib folder
  invoke MessageBox, hWnd, ADDR memHandle, NULL, MB_OK
  invoke GlobalFree, memHandle
showPointerValue endp

arafel

invoke MessageBox, hWnd, memHandle, NULL, MB_OK


also it would be better to create a buffer in the data section, instead of allocating such small chunk.

pavellus

After removing ADDR i see nothing ( grey box ) and message about close the process by windows :)

arafel

Well the parameters for dwtoa are wrong as well. Sorry, I haven't noticed it the first time.
First param should be a value to convert and second one should point to the output buffer.

invoke dwtoa, handle, memHandle

Ratch

#4
 pavellus,

     Here it is.   Note that some parameters are PUSHed when they are available, and not when they are needed.  This saves instructions and memory.  Ask if you have any questons.  Ratch

.CODE

SPV STRUC
return    DWORD ?
handle    DWORD ?
SPV ENDS

showPointerValue:
  invoke GlobalAlloc, LMEM_FIXED, 80     ;return eax - handle to allocated 20 bytes

  PUSH EAX                               ;****PUSH for GlobalFree below
  PUSH EBP                               ;****PUSH for MessageBox below
  PUSH TEXT('showPointerValue',0)        ;****PUSH for MessageBox below
  PUSH EAX                               ;****PUSH for MessageBox below


  INVOKE wsprintf,EAX,TEXT('The handle value is %08X',0),[ESP.SPV.handle+4*DWORD]

  PUSH EBP
  CALL MessageBox                        ;****parameters already pushed above

  CALL GlobalFree                        ;****parameter already pushed above

  RET DWORD
;-------------------------------------------------------------------------------

START:
XOR EBP,EBP
PUSH 012345678H
CALL showPointerValue
INVOKE ExitProcess,EBP
END START

[attachment deleted by admin]

morlok

Try this (only with a local buffer instead GlobalAlloc).


showPointerValue proc handle:DWORD
  LOCAL LocalBuffer[20]:BYTE

  invoke dwtoa, handle, ADDR LocalBuffer
  invoke MessageBox, hWnd, ADDR LocalBuffer, NULL, MB_OK

showPointerValue endp



.Regards

pavellus