Is it possible to get the address of a dialog control?

Started by rogerio, April 22, 2009, 10:15:08 PM

Previous topic - Next topic

rogerio

Is there any way to get the address of a Windows dialog control such as a edit? I haven't seen any direct answer, but I am assuming that the operating system must handle the issue. I would be nice to use ASM instead of an API.

donkey

Generally the answer is no, at least not by using the API and there are problems with different Windows versions. Some controls allow you to set your own buffers but generally you have to manage the display, for example a virtual listview. But if you are just looking to have direct access to an edit controls buffer you can use EM_SETHANDLE.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

rogerio

Thanks donkey. I took a stab at your suggestion using EM_GETHANDLE and came up empty.

invoke GetDlgItem,hWin,IDC_EDT1  , Multiline edit
mov hIDC_EDT1,eax
invoke SendMessage,hIDC_EDT1,EM_GETHANDLE,0,0
mov hMem_Buf,eax
invoke LocalUnlock,hMem_Buf
mov edi,hMem_Buf
mov al,65   ; Char 'A'
                stosb

'A' did not show up in the edit.

donkey

Hi,

Read my post I said EM_SETHANDLE, EM_GETHANDLE is not available to 32 bit applications...

invoke GlobalAlloc,GMEM_FIXED,32768
mov [hGlobal],eax
mov edi,eax
invoke SendDlgItemMessage,[hwnd],1001,EM_SETHANDLE,eax,0
mov al,"a"
mov ecx,10
rep stosb


Quote from: MSDN EM_GETHANDLEWindows 95/98/Me: Although this message returns a nonzero value, the resulting value is not useful to a 32-bit application.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

rogerio

2 issues:

1. No matter what ecx is changed to, it will try to put 3 "a"s into the edit.
2. MS PSDK says to access EM_GETHANDLE before setting memeory address; I simple used the existing address as the access point. See below:
;-----------------------------------------------------------------------
EM_SETHANDLE Message

--------------------------------------------------------------------------------

Sets the handle of the memory that will be used by a multiline edit control.

Syntax


To send this message, call the SendMessage function as follows.
lResult = SendMessage(      // returns LRESULT in lResult     (HWND) hWndControl,      // handle to destination control     (UINT) EM_SETHANDLE,      // message ID     (WPARAM) wParam,      // = (WPARAM) (HLOCAL) wParam;    (LPARAM) lParam      // = 0; not used, must be zero );   
Parameters

wParam
A handle to the memory buffer the edit control uses to store the currently displayed text instead of allocating its own memory. If necessary, the control reallocates this memory.
lParam
This parameter is not used.
Return Value

This message does not return a value.

Remarks

Before an application sets a new memory handle, it should send an EM_GETHANDLE message to retrieve the handle of the current memory buffer and should free that memory.

An edit control automatically reallocates the given buffer whenever it needs additional space for text, or it removes enough text so that additional space is no longer needed.

Sending an EM_SETHANDLE message clears the undo buffer (EM_CANUNDO returns zero) and the internal modification flag (EM_GETMODIFY returns zero). The edit control window is redrawn.

Rich Edit: The EM_SETHANDLE message is not supported. Rich edit controls do not store text as a simple array of characters.

Message Information

Header Declared in Winuser.h, include Windows.h
Minimum operating systems Windows NT 3.1

See Also

Edit Controls Overview, EM_CANUNDO, EM_GETHANDLE, EM_GETMODIFY

drizz

.data
mytext db "mytextmytextmytextmytextmytextmytext",0
.code
invoke SendMessage,hEdt,EM_GETHANDLE,0,0
mov hEdtBufOld,eax
invoke LocalSize,hEdtBufOld
.if eax < sizeof mytext
invoke LocalReAlloc,hEdtBufOld,sizeof mytext,0
mov hEdtBufOld,eax
.endif
invoke LocalLock,hEdtBufOld
mov esi,offset mytext
mov edi,eax
mov ecx, sizeof mytext
rep movsb
invoke LocalUnlock,hEdtBufOld
invoke SendMessage,hEdt,EM_SETHANDLE,hEdtBufOld,0
The truth cannot be learned ... it can only be recognized.

rogerio

Thanks drizz, it worked. BTW, are listview and edit controls the only ones accessible this way? MS doesn't provide a lot of information on their addressing that I can find when it comes to the operating system.