The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: pavellus on July 04, 2006, 04:24:56 PM

Title: displaying pointer value in messagebox problem
Post by: pavellus on July 04, 2006, 04:24:56 PM
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
Title: Re: displaying pointer value in messagebox problem
Post by: arafel on July 04, 2006, 04:39:46 PM
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.
Title: Re: displaying pointer value in messagebox problem
Post by: pavellus on July 04, 2006, 04:47:18 PM
After removing ADDR i see nothing ( grey box ) and message about close the process by windows :)
Title: Re: displaying pointer value in messagebox problem
Post by: arafel on July 04, 2006, 05:04:32 PM
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
Title: Re: displaying pointer value in messagebox problem
Post by: Ratch on July 04, 2006, 11:55:22 PM
 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]
Title: Re: displaying pointer value in messagebox problem
Post by: morlok on July 05, 2006, 08:56:16 AM
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
Title: Re: displaying pointer value in messagebox problem
Post by: pavellus on July 05, 2006, 09:17:40 AM
Ok, thank you, now it is working.