- Daniel Vivier
- PowerBuilder
- Friday, 1 March 2019 10:06 PM UTC
This is in PB 2017 R3. I'm having a weird problem where some code I'm using to try to determine whether an instance of my app is already running is somewhat randomly crashing the compiled program (or PB if I run from there or use the debugger).
I have an external function declaration as follows:
FUNCTION long GetWindowText(ulong handle, ref string wintext, long length) Library "user32.dll" alias for "GetWindowTextW"
The I call it as follows (having determined the ULong handle value ulHwnd somehow):
String lsTitle, lsTitleStart = "text to search for"
lsTitle = String(200)
0 then
if Pos(lsTitle, lsTitleStart) = 0 then
....
I have seen in the debugger where the GetWindowText succeeds (I see a value for lsTitle) but then PB crashes on the next line, looking for lsTitleStart in lsTitle. Other times it crashes other places in the larger function containing this (or sometimes doesn't crash if I put enough debugging messageboxes into the code at various places).
So my intuition is that the GetWindowText is somehow screwing things up in PB's internal memory. But I don't know how. And oddly enough, another function that calls GetWindowText seems to always work. But I'm pretty sure it's what is causing the problem in this function, because if I eliminate that call, it never crashes (so far!).
Any thoughts, or other similar experience? Thanks.
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.