Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Text Grab program


  • Please log in to reply
27 replies to this topic

#1 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 04 March 2012 - 08:02 PM

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







#2 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 04 March 2012 - 10:51 PM

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

#3 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 07 March 2012 - 07:51 PM

Bump...

Is there anyone able to help with the DLL implementation of TextGrab.

Thanks.

#4 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 12:15 PM

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.

#5 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 10,439 posts

Posted 16 March 2012 - 01:18 PM

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 an XP machine, 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!

 

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. Latin Square password generator

 

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.


#6 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 05:59 PM

Hi BrewMan,

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 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 06:00 PM

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.

#8 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 06:26 PM

The below is the link the C and Visual basic examples:

http://www.renovation-software.com/en/tgsdk-doc/capture-from-hwnd.html

#9 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 16 March 2012 - 10:30 PM

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, 16 March 2012 - 11:15 PM.

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#10 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 10:48 PM

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.

#11 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 16 March 2012 - 10:53 PM

All that means nothing to me I'm afraid

Did all three of those produce the same error? (I don't need to see any more of the errors)

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#12 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 11:03 PM

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

#13 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 16 March 2012 - 11:09 PM

Yes

Try wchar instead of char.

for the record there is no str/wstr in structs (oops)

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#14 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 11:17 PM

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

#15 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 16 March 2012 - 11:33 PM

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
 
 
OMG! Women are the cows of people.


#16 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 16 March 2012 - 11:52 PM

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

#17 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 17 March 2012 - 12:06 AM

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, 17 March 2012 - 12:08 AM.

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#18 nznet

nznet

    Seeker

  • Active Members
  • 19 posts

Posted 17 March 2012 - 12:14 AM

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

#19 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 17 March 2012 - 12:23 AM

DllCall returns an array, so...

If IsArray($Text) Then
MsgBox(0,"Text",$Text[0])

Else

MsgBox(0,"Error",@error)
Endif

Edited by JohnOne, 17 March 2012 - 12:24 AM.

AutoIt Absolute Beginners Require a serial
 
 
OMG! Women are the cows of people.


#20 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 12,889 posts

Posted 17 March 2012 - 12:28 AM

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
 
 
OMG! Women are the cows of people.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users