Macro Scheduler is great!
I do have an issue. For some reason, this code snippet:
------
VBSTART
Function OcrText(x1,y1,x2,y2)
OcrRead.CaptureWindow(x1,y1,x2,y2)
ocrText=OcrRead.Text
End Function
VBEND
VBEval>OcrText(%Left%,%Top%,%Right%,%Bottom%),sResult
MessageModal>sResult
-------
works at first, but eventually leads to the message box showing unprintable characters, and then access violations.
However, this code does not:
--------
VBSTART
Dim gsText
Function OcrText(x1,y1,x2,y2)
OcrRead.CaptureWindow(x1,y1,x2,y2)
gsText=OcrRead.Text
End Function
VBEND
VBEval>OcrText(%Left%,%Top%,%Right%,%Bottom%),sResult
VBEval>gsText,sResult
MessageModal>sResult
---------
Although clunkier looking, it works fine time after time, though I worry that something I am doing wrong will eventually lead to memory corruption and a script crash.
(In both cases the Macro Scheduler variables are loaded with the screen coordinates of a text painted onto a control. The OcrRead control was assigned with a CreateObject command and initialized in the same way, and terminated/cleaned up in the same way when the script is done.)
The OcrRead class is a third party control class, and may have a bug. However, I wonder if there is something I am intrinsically doing wrong in setting up my VBScript function-- for instance, should I "allocate" memory by preloading the OcrText function in the first example code with enough characters to hold the resulting screen?
VBScript functions, activeX, and access violations
Moderators: JRL, Dorian (MJT support)
Actually, it turned out that both the above sets of code still caused crashes.
The problem turned out to be that the activeX control returned a BSTR (bstring)-- and I needed to convert it to a CSTR.
So, the code below works without any access violations or crashing.
The problem turned out to be that the activeX control returned a BSTR (bstring)-- and I needed to convert it to a CSTR.
So, the code below works without any access violations or crashing.
Code: Select all
VBSTART
Function OcrText(x1,y1,x2,y2)
OcrRead.CaptureWindow(x1,y1,x2,y2)
ocrText=CStr(OcrRead.Text)
End Function
VBEND
VBEval>OcrText(%Left%,%Top%,%Right%,%Bottom%),sResult
MessageModal>sResult