Text Grab program
#1
Posted 04 March 2012 - 08:02 PM
I don't believe this program was using OCR... not sure how it is doing it but the output text it gave many on all tests across a variety of windows applications was 100% perfect. More than I can say for the OCR trials.
I have included the link to the program's SDK above. I have included below a C++ source code example of the implementation of TextGrab. I would like to know how I can simply call the dll with parameters similar to using Deskexperinces TcaptureX. Given TCaptureX example of this below.
; TCaptureX example that captures all the text of the active window
$oTCX = ObjCreate("TCaptureX.TextCaptureX")
$hWnd = $oTCX.GetActiveWindowHwnd()
$text = $oTCX.GetFullTextAA($hWnd)
; TCaptureX eample taht captures all the text of the rectangle specified
$XY = WinGetPos($windowtitle)
$oTCX = ObjCreate("TCaptureX.TextCaptureX")
$hWnd = $oTCX.GetActiveWindowHwnd()
$text = $oTCX.GetTextFromRect($hWnd, $XY[0] + 28, $XY[1] + 177, 485, 237)
Below is the Cpp code example I have for Text Grab.
// demo.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "demo.h"
#include "MainDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
BEGIN_MESSAGE_MAP(CdemoApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::onhelp)
END_MESSAGE_MAP()
CdemoApp::CdemoApp()
{
}
CdemoApp theApp;
BOOL CdemoApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
CoInitialize(NULL);
{
CMainDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
}
CoUninitialize();
return FALSE;
}
I'd like to be able to do the same as the examples I have given for TCaptureX but not sure how to implement the DLL from the C++ code.
Would realy appreciate your help.
Kind Regards,
Stephen
#2
Posted 04 March 2012 - 10:51 PM
#3
Posted 07 March 2012 - 07:51 PM
Is there anyone able to help with the DLL implementation of TextGrab.
Thanks.
#4
Posted 16 March 2012 - 12:15 PM
$oTCX = ObjCreate("tgsdkx.TextGRABSDK")
$Title = "Notepad"
$hwnd = Dec(StringTrimLeft(WinGetHandle($Title), 2))
local $Test = ""
$Text = $oTCX.CaptureFromHWND($hWnd, $test)
MsgBox(0,"Text",$Text)
There appears to be an error on line:
$Text = $oTCX.CaptureFromHWND($hWnd, $test)
Maybe I have not passed the parameter correctly.
Please help.
#5
Posted 16 March 2012 - 01:18 PM
How to ask questions the smart way!
Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.
Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.
_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.
#6
Posted 16 March 2012 - 05:59 PM
I was following the example laid out here for TCaptureX:
http://www.autoitscript.com/forum/topic/30760-dllcall-tcapturexdll/page__st__20__p__575295__hl__ocr%20dec__fromsearch__1#entry575295
I also tried and it still does not work:
;$hWnd = WinGetHandle($Title) ; title being name of window
Cheers,
Stephen
#7
Posted 16 March 2012 - 06:00 PM
Please if someone can help.
#8
Posted 16 March 2012 - 06:26 PM
http://www.renovation-software.com/en/tgsdk-doc/capture-from-hwnd.html
#9
Posted 16 March 2012 - 10:30 PM
I'm not even certain you can pass a struct to an object type, but it's worth a go.
$StrPtr = DllStructGetPtr($Struct)
Pass $StrPtr as secong arg
Or
$Struct = DllStructCreate('char[1024]')
By the way, people don't do paid work here.
Edited by JohnOne, 16 March 2012 - 11:15 PM.
#10
Posted 16 March 2012 - 10:48 PM
Thanks for your suggestions. I have tried them both and now I get the following:
Exception occured during text capture. Please see the log fil.
The log file is list below:
<?xml version="1.0"?>
-<Exception><ExceptionRecord LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xb04" FunctionName="ClearCustData" ExceptionAddress="74A195CB" ExceptionDescription="EXCEPTION_ACCESS_VIOLATION" ExceptionCode="0xc0000005" CommandLine=""C:Program Files (x86)AutoIt3AutoIt3.exe" "G:SanDiskSecureAccessNew MidasTextgrabtextgrab2.au3" " ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe"/><Processor NumberOfProcessors="8" Level="Intel Pentium Pro or Pentium II" Architecture="PROCESSOR_ARCHITECTURE_INTEL"/><OperatingSystem CSDVersion="Service Pack 1" BuildNumber="7601" MinorVersion="1" MajorVersion="6"/><Modules/>-<CallStack><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xb05" FunctionName="ClearCustData" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x74a195cb" FrameNumber="1"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xbdd6" FunctionName="VarDecNeg" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x749e239f" FrameNumber="2"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0xa63" FunctionName="LoadRegTypeLib" ModuleName="C:Windowssyswow64OLEAUT32.dll" ReturnAddress="0x749b3c91" FrameNumber="3"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:TextGRABSDKtgsdkx.dll" ReturnAddress="0x365108" FrameNumber="4"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x20b281" FrameNumber="5"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x20e373" FrameNumber="6"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1b961e" FrameNumber="7"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19af90" FrameNumber="8"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x199303" FrameNumber="9"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1996c0" FrameNumber="10"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19d87e" FrameNumber="11"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x19d967" FrameNumber="12"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x0" FunctionName="" ModuleName="C:Program Files (x86)AutoIt3AutoIt3.exe" ReturnAddress="0x1a648e" FrameNumber="13"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x12" FunctionName="BaseThreadInitThunk" ModuleName="C:Windowssyswow64kernel32.dll" ReturnAddress="0x758e339a" FrameNumber="14"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x63" FunctionName="RtlInitializeExceptionChain" ModuleName="C:WindowsSysWOW64ntdll.dll" ReturnAddress="0x77289ef2" FrameNumber="15"/><Frame LineDisplacement="0x0" LineNumber="0" Filename="" FunctionDisplacement="0x36" FunctionName="RtlInitializeExceptionChain" ModuleName="C:WindowsSysWOW64ntdll.dll" ReturnAddress="0x77289ec5" FrameNumber="16"/></CallStack></Exception>
Do you have any suggestions?
Thanks again for taking the time to answer my post.
#11
Posted 16 March 2012 - 10:53 PM
Did all three of those produce the same error? (I don't need to see any more of the errors)
#12
Posted 16 March 2012 - 11:03 PM
I tried:
1)
$Struct = DllStructCreate('str') ; maybe wstr.
$StrPtr = DllStructGetPtr($Struct)
$Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr)
2)
$Struct = DllStructCreate('wstr') ; maybe wstr.
$StrPtr = DllStructGetPtr($Struct)
$Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr)
3)
$Struct = DllStructCreate('char[1024]')
$StrPtr = DllStructGetPtr($Struct)
$Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr)
I take it that I read your suggestions correctly. And yes they all produced the same error.
Thanks
Stephen
#13
Posted 16 March 2012 - 11:09 PM
Try wchar instead of char.
for the record there is no str/wstr in structs (oops)
#14
Posted 16 March 2012 - 11:17 PM
I have been using the following at the top of my script. Something I found yesterday reading through the forum:
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
Func MyErrFunc()
Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
"err.number is: " & @TAB & hex($oMyError.number,8) & @CRLF & _
"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oMyError.helpcontext _
)
Endfunc
I made the chnage to wchar as per your suggestion. I now do not get the other message but one generated from the code above that states:
We intercepted a COM Error!
err.windescription Uspecified error
err.number is: 80020009
The error is stated to be on the following line:
$Text = $oTCX.CaptureFromHWND($hWnd,$StrPtr)
Thanks,
Stephen
#15
Posted 16 March 2012 - 11:33 PM
It's a possibility that the second arg (which I'm assuming is an out parameter that the method modifies)
might need to be passed by ref, which I don't think autoit does.
But again, worth a pop.
$Struct = DllStructCreate('wchar[1024]')
;$StrPtr = DllStructGetPtr($Struct)
$Text = $oTCX.CaptureFromHWND($hWnd,ByRef $Struct )
#16
Posted 16 March 2012 - 11:52 PM
The Visual Basic code for the calling of the DLL is:
[Visual Basic]
object.CaptureFromHWND(
ByVal hwnd As INT_PTR,
ByRef text As String
)
I now get an error in the expression by placing ByRef where it is.
Thanks,
Stephen
#17
Posted 17 March 2012 - 12:06 AM
a pointer to char buffer instead of a reference.
That is of course unless something has changed since your version of autoit
like in a beta or something.
Best of luck.
EDIT:
A long shot might be that it is possible to call a dll directly, but you would have
to ask the developer that one.
Edited by JohnOne, 17 March 2012 - 12:08 AM.
#18
Posted 17 March 2012 - 12:14 AM
I have been looking at the calling directly and going through the tutorial I found on the forum a few days ago.
I have tried the following:
$hWnd = WinGetHandle("Notepad")
MsgBox(0,"hWnd",$hWnd)
$Struct = DllStructCreate('wchar[1024]')
$text = DllCall("tgsdkx.dll","int","CaptureFromHWND","hwnd",$hwnd,"ptr", $struct)
MsgBox(0,"Text",$Text)
This time I get no errors but the result is displayed as 0.
Thanks,
Stephen
#19
Posted 17 March 2012 - 12:23 AM
If IsArray($Text) Then
MsgBox(0,"Text",$Text[0])
Else
MsgBox(0,"Error",@error)
Endif
Edited by JohnOne, 17 March 2012 - 12:24 AM.
#20
Posted 17 March 2012 - 12:28 AM
$hWnd = WinGetHandle("Notepad")
MsgBox(0,"hWnd",$hWnd)
$Struct = DllStructCreate('wchar[1024]')
$StrPtr = DllStructGetPtr($Struct)
$text = DllCall("tgsdkx.dll","int","CaptureFromHWND","hwnd",$hwnd,"ptr", $StrPtr )
If IsArray($Text) Then
MsgBox(0,"Text",$Text[0])
Else
MsgBox(0,"Error",@error)
Endif
Of course that if it worked would give you the return from the function, If indeed there is one.
The values you want would be help in the struct, which you would get with DllStructGetData()
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users





