Discussion:
Read/write status of Check Box via DLL in a 'host' EXE.
(too old to reply)
i***@arcor.de
2006-02-19 12:09:07 UTC
Permalink
I wrote a DLL communicating with another program. The DLL is invoked by
the EXE via an alert process. So they use the same memory.
The DLL uses the predefined API functions inside the EXE.
For one essential task however there is no API function included.
I want to read/write the status of a single Check Box inside the dialog
of The
EXE.
Well, I managed already to do so but always have to invoke the
EXE's tabbed dialog first to get access to the check box ID to
manipulate it's
status. I want to avoid this nasty procedure and ask You here if anyone
could tell me if I could directly change the check box status via
memory access. With WINHEX Forensic it is possible to access the
corresponding byte I found already in memory, but how could I do it
programaticaly?

Bert
Michael Mattias
2006-02-19 13:25:35 UTC
Permalink
Post by i***@arcor.de
I wrote a DLL communicating with another program. The DLL is invoked by
the EXE via an alert process. So they use the same memory.
The DLL uses the predefined API functions inside the EXE.
I want to avoid this nasty procedure and ask You here if anyone
could tell me if I could directly change the check box status via
memory access.
No, you may not; at least not in any supported or reliable manner. Windows
reserves the right to move things around as it sees fit. I don't think it
actually DOES do this IN THE PARTICULAR CASE OF A CONTROL'S CURRENT STATE,
but all access to objects within Windows is supported only using the handles
provided for that purpose.
Post by i***@arcor.de
Well, I managed already to do so but always have to invoke the
EXE's tabbed dialog first to get access to the check box ID to
manipulate it's status.
That should NEVER be necessary. Once you have a handle to the checkbox
control (or its parent window/dialog), you can always interrogate or
manipulate the check status. Sounds like you are passing the wrong
window/control handle to your function.
Post by i***@arcor.de
For one essential task however there is no API function included.
I want to read/write the status of a single Check Box inside the dialog
of The EXE.
SendMessage hCtrl, BM_GETCHECK/ BM_SETCHECK, wparam, lparam


--
Michael Mattias
Tal Systems, Inc.
Racine WI
***@talsystems.com
i***@arcor.de
2006-02-19 20:09:05 UTC
Permalink
Hi Michael,
The following is what I've done until now.
:
Function SimulateButtonClickWithParams(hWndButton As Long, lCheck As
Long) As Long
'INPUT: hWndButton als Handle des Buttons, lCheck = 1 oder 0
local lRet As Long
local hWndParent As Long

hWndParent = GetParent(hWndButton)
If hWndParent <> 0& Then
If SendMessageLong(hWndButton, BM_GETCHECK, 0&, 0&) = 1& Then
If lCheck = 0& Then 'uncheck
lRet = SendMessageLong(hWndButton, BM_CLICK, 0&,
lCheck) 'lCheck = 0
End If
ElseIf SendMessageLong(hWndButton, BM_GETCHECK, 0&, 0&) = 0&
Then
If lCheck = 1& Then
lRet = SendMessageLong(hWndButton, BM_CLICK, 0&,
lCheck) 'lCheck = 1
End If
End If
SimulateButtonClickWithParams = lRet
End If
End Function

The button handle is correct but the function works only when I first
programaticaly show the tab control where the button resides. I wonder
why.....

Bert
Michael Mattias
2006-02-19 22:13:34 UTC
Permalink
Post by i***@arcor.de
The following is what I've done until now.
Function SimulateButtonClickWithParams(hWndButton As Long, lCheck As
Long) As Long
'INPUT: hWndButton als Handle des Buttons, lCheck = 1 oder 0
local lRet As Long
local hWndParent As Long
hWndParent = GetParent(hWndButton)
If hWndParent <> 0& Then
If SendMessageLong(hWndButton, BM_GETCHECK, 0&, 0&) = 1& Then
If lCheck = 0& Then 'uncheck
lRet = SendMessageLong(hWndButton, BM_CLICK, 0&,
lCheck) 'lCheck = 0
....
Post by i***@arcor.de
The button handle is correct but the function works only when I first
programaticaly show the tab control where the button resides. I wonder
why.....
It only works when that dialog is in the foreground (techinically, when it's
the active window) because an inactive window cannot receive a BM_CLICK
message. (It thinks it came from the keyboard, but the focused window is the
active window, and only the focused window can recieve keyboard input).

Change to using BM_SETCHECK message. (Didn't I say that before? It's deja vu
all over again.)

Also as a matter of style, don't use "0" and "1". Use %BST_CHECKED /
%BST_UNCHECKED. It will be a lot easier to maintain the program that way.

(FWIW, the hWndParent code in there does nothing).

--
Michael Mattias
Tal Systems, Inc.
Racine WI
***@talsystems.com
i***@arcor.de
2006-02-20 09:04:05 UTC
Permalink
Yes, you are right with the syntax. The code I use was translated from
C to PB. Avoiding to get to know the PB constant names I first used 0
and 1. ;-)
hWndparent is the rest of debugging inside a loop finding the button
ID.
Well, then there seem so be no proper way to prevent the 'dialog
invoke' procedure. Perhaps I'll find a different solution after
detecting the original function address inside the EXE. I'll once again
have a deeper look inside the EXE's lib file today.

Norbert

Loading...