sss123next
10th November 2012 17:44 UTC
How to attach data to window handle
Hi all, i need to attach some data to windows handle for later use, i trying to use {Get/Set}WindowLong, but with no success, i trying following
!define GWL_USERDATA -21
System::Call 'user32::SetWindowLong(i $hwnd, i ${GWL_USERDATA}, tr3)'
System::Call 'user32::GetWindowLong(i $hwnd, i ${GWL_USERDATA}) i.r4'
MessageBox MB_OK "USERDATA $4"
i storing in $3 some text data, which i need to check later, but in $4 i have pointer address, how i can dereference it ?, and another problem, looks like windows loosing it's style's after this calls, is here another right way to do what i need ?
Anders
10th November 2012 22:21 UTC
Don't use GWL_USERDATA, NSIS already uses it.
If you want to store data "on" a hwnd, use user32::SetProp. If the control is on a nsDialogs page, use nsDialogs::SetUserData.
If you want to store a string you cannot use the trX syntax, you need to allocate real memory with the system plugin and then use the struct syntax to copy strings in and out...
sss123next
10th November 2012 22:30 UTC
thx for info.
do i need to call free after nsDialogs::SetUserData call ?
kichik
11th November 2012 02:23 UTC
You only need to allocate memory if you call user32::SetProp or user::SetWindowLong directly. nsDialogs::SetUserData takes care of memory allocation for you. Every control you create has memory set aside for user data. nsDialogs frees this memory when the control is destroyed along with the dialog.
sss123next
11th November 2012 08:10 UTC
good, thx.