Jump to content

DLLCall TCaptureX.dll


Recommended Posts

Deskperience has a very nice OCR DLL that is relatively cheap, $40. They have source code to show how to use it in several languages. Normally I could load PE Explorer, look at the exports and easily figure out the right DLLCall format in AutoIt through trial and error. I can't for the life of my figure out this DLL because the exports are strange, I imaging it has to do with the licensing and such.

C++ Source using the DLL. This is inside a function to get OCR text from a given rect on a certain window by handle.

ITextCaptureXPtr pCaptureObj = NULL;
    HRESULT hr = pCaptureObj.CreateInstance(__uuidof(TextCaptureX));
    if(FAILED(hr))
    {
        ShowErrorMessage();
        return;
    }
    long hWndTarget = GetValueFromHexCode(m_strHandle);
    
    _bstr_t bstrResult;
    try
    {
        bstrResult = pCaptureObj->GetTextFromRect(hWndTarget, m_nX, m_nY, m_nWidth, m_nHeight);
    }
    catch(...)

There are several DLLs in the package and I assume they all talk to each other with registration and licensing information. In the C++ code I only see a reference to TextCaptureX and no other DLLs.

TCaptureX.dll - Exports.

DllCanUnloadNow
DllGetClassObject
DllRegisterServer
DllUnregisterServer
_PathFindExtensionW@4

TCapture.dll looks to be the one that does the magic though. Here is the export that looks to handle the rect function.

?GetTextFromRect@@YAPAGPAUHWND__@@UtagRECT@@PAUtagLOGFONTW@@PAK3PAPAG@Z
Undecorated C++ Function:
unsigned short * __cdecl GetTextFromRect(struct HWND__ *,struct tagRECT,struct tagLOGFONTW *,unsigned long *,unsigned long *,unsigned short * *)

I only know enough C++ to get myself in trouble so I'm at a loss. Hope one of the big brains around here and descramble this all for me. They have a trial of the DLL on their website if anyone wants to take a stab at it.

http://www.deskperience.com/textcapture/index.html

Link to comment
Share on other sites

  • Moderators

You bought this thing, and they didn't supply the API calls?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

They only provide source code examples for C++, C# and VB.

The VB would probably be easier for someone to translate here, for those of us that know as much C++ as you do lol... I don't know VB either, but I've been able to translate a few things for others.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

VB Code for using rect.

Reference=*\G{92657C70-D31B-4930-9014-379E3F6FB91A}#1.0#0#..\..\..\..\Program Files\Deskperience\Text Capture\TCaptureX.dll#TCaptureX 1.0 Type Library


Public Sub CaptureRectangle()
On Error GoTo Err
    Dim objCapture As New TextCaptureX
    Dim hwnd As Long
    Dim str As String
    Dim res As String
    
    str = "&H" & txtHandle.Text
    hwnd = Val(str)
  
    txtResult.Text = objCapture.GetTextFromRect(hwnd, CLng(txtX.Text), CLng(txtY.Text), CLng(txtWidth.Text), CLng(txtHeight.Text))
    Exit Sub
Err:
    ShowMessageNotRegistered
End Sub
Link to comment
Share on other sites

  • Moderators

Here's a stab at her:

Func _CallGetText($hWnd, $iXTopLeft, $iYTopLeft, $iXBottomRight, $iYBottomRight)
    $iXBottomRight = ($iXBottomRight - $iXTopLeft)
    $iYBottomRight = ($iYBottomRight - $iYTopLeft)
    If IsString($hWnd) Then $hWnd = WinGetHandle($hWnd)
    Local $sDllLocation = @ScriptDir & '\TCaptureX.dll'
    Local $aDll = DllCall($sDllLocation, 'str', 'GetTextFromRect', 'hwnd', $hWnd, 'long', $iXTopLeft, _
                'long', $iYTopLeft, 'long', $iXBottomRight, 'long', $iYBottomRight)
    If @error = 0 Then Return $aDll[0]
    Return SetError(1, 0, 0)
EndFunc
Didn't run it so good luck :whistle: Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Valiant effort but no dice. At least it doesn't crash, just returns 0.

Would I have to create an Object to use it similar to the VB code? Don't see any examples in the help for creating an object against a dll and have never used this feature in AutoIt.

Link to comment
Share on other sites

  • Moderators

Valiant effort but no dice. At least it doesn't crash, just returns 0.

Would I have to create an Object to use it similar to the VB code? Don't see any examples in the help for creating an object against a dll and have never used this feature in AutoIt.

I'm sure you did this already, you did change the @ScriptDir & '\TCaptureX.dll' to the correct location right? (hoping that's the right DLL too)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Yep, change it to the same dir as the autoit script.

@ScriptDir was the same anyway... (The DLL is there right, and you don't have to have any others in it's place?)

I'm curious now, think I'll download it... do you have to have the full version to work the API or do you know?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

sorry, I ment I have the autoit script in the same dir as the dll and yes I changed the code to reflect that.

I'm pretty sure you have full access to the whole API with the trial version.

Unfortunately, I can't get it to work either... I get a component error occasionally if I don't run the script from the location... But more so to the point, I think you need to use DLLStructCreate()/Ptr() and I don't know how to use them correctly.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Almost got it working. Took a step back to work with the simplest function in the dll and I've got that working with objects.

$oShell = ObjCreate("TCaptureX.TextCaptureX")
$res = $oShell.CaptureActiveWindow

MsgBox(0,0,$res)
Edited by CyberGlitch
Link to comment
Share on other sites

Ok, figured the hard part out. Now to figured out the handle part for windows.

;autoit hand returns 0x000B093C
$hnd = 723260

$oShell = ObjCreate("TCaptureX.TextCaptureX")
$res = $oShell.GetTextFromRect(hnd, 0, 0, 200, 200)

Now how do I convert the window handles autoit gives to the type I need. I'm guesing it's a hex conversion?! :">

Link to comment
Share on other sites

Ok, inside autoit how would I convert b093c to be 723260? b093c is the handle of the window. Looking at the C# source code that I can understand it converts the b093c to 723260.

//txtHandle.Text = b093c 
int hWndTarget = System.Convert.ToInt32(txtHandle.Text, 16);

If I plug 723260 directly into autoit it works great! :whistle: Just need to get that number automatically inside autoit now.

Link to comment
Share on other sites

  • Moderators

This might give you insight:

MsgBox(0, '', 0x000B093C)

Edit:

If your really feeling like you have to have a decimal then you could always do this as well:

$Title = WinGetTitle('')
$hwnd = Dec(StringTrimLeft(WinGetHandle($Title), 2))
MsgBox(0, '', $hwnd)oÝ÷ ØGb·c«¶¬jëh×6$Title = WinGetTitle('')
$hwnd = Execute(WinGetHandle($Title))
MsgBox(0, '', $hwnd)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Hmm, that fails for me :)

Errrr!!! NM I'm a Fargen :whistle:

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • 3 months later...

It just aint working for me, and i have no clue why. Window-Handle seems to be fine, i can minimize and maximize windows with it for example, but no luck with GetTextFromRect, result is 0.

I still think it has something to do with the hwnd, because i can scan with CaptureActivewindow. When i try to activate another window and then use CaptureActiveWindow, i dont get a result either, i managed only to scan the Scite-window with it so far.

Any ideas?

Opt("WinTitleMatchMode",2)
$Title = WinGetTitle('Unbenannt')
$hwnd = Dec(StringTrimLeft(WinGetHandle($Title), 2))
;$hwnd = Execute(WinGetHandle($Title))

$oShell = ObjCreate("TCaptureX.TextCaptureX")
;$res = $oShell.CaptureActiveWindow
$res = $oShell.GetTextFromRect($hwnd, 0, 0, 500, 600)
MsgBox(0,$hwnd,$res)
Link to comment
Share on other sites

  • Moderators

Is it standard window font or is it graphic font? (makes a difference)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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