Jump to content

Text Grab program


nznet
 Share

Recommended Posts

I have tried every OCR utility setup on this forum and more with AutoitScript. However all the DLL'S have their good and bad points. Yesterday I came across the TextGrab SDK at http://www.renovation-software.com/ . I tried their demo and was amazed at how well it read the text from the application. One feature was just clicking on the text and it captured the word or section the word was contained within.

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

Link to comment
Share on other sites

HI, Looking at the Control Viewer and other posts on the forum similar the last hour after reading your post. Still not having any luck grabbing the test of the control. Will perservere. Anyhow thanks for your quite reply....

Link to comment
Share on other sites

  • 2 weeks later...

Is there anyone who can help me. I have been in touch with the authors of Text Grab and they have be helpful in giving some suggestions but they have never used AutoITScript. The closest I have gotten so far with their help is:

$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.

Link to comment
Share on other sites

Why are you converting the handle to Decimal and also trimming 2 characters from it? You need the handle and removing characters from the pointer doesn't seem to make much sense to me if you are expecting to be able to find the window the handle applies to.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

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 editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I am happy to pay one of the experienced users privately to work this out for me as it is frustrating me so much as I have been trying to work this out for over a week now.

Please if someone can help.

Link to comment
Share on other sites

Looks like the second argument needs to be a pointer to an empty string, or perhaps a char[] array of sufficient size.

I'm not even certain you can pass a struct to an object type, but it's worth a go.

$Struct = DllStructCreate('str') ; maybe wstr EDIT: no str/wstr structs.

$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

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi John,

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.

Link to comment
Share on other sites

Hi John,

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

Link to comment
Share on other sites

Hi John,

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

Link to comment
Share on other sites

I'm running out of ideas, which are few anyway, and probably wrong.

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 )

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi John,

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

Link to comment
Share on other sites

Well, I'm not 100% on this, but I think you might be out of luck If it will not accept

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

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Hi John,

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

Link to comment
Share on other sites

Sorry

$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()

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...