Calling an SDK from AHK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Calling an SDK from AHK

21 Feb 2017, 12:47

I need to call an SDK from my AHK code. The SDK gives example calls in C#, C++, Delphi, Java, PHP, VB, and VBScript/ASP (I don't program in any of those languages). What would be the best language example to start with in order to convert/translate the SDK calls into AHK? Thanks, Joe
SifJar
Posts: 398
Joined: 11 Jan 2016, 17:52

Re: Calling an SDK from AHK

21 Feb 2017, 14:08

What sort of SDK is it? Is there a DLL file distributed?

It might be helpful if you can share a link to the SDK and/or it's documentation.
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

21 Feb 2017, 19:02

I'm under an NDA on this project. I'll see if I can get written permission to share publicly. But in the meantime, is it possible to say on a general/theoretical basis if code from one of those six languages is better than any of the others for the purpose of converting/translating the SDK calls into AHK? For example, I've learned on some other threads here that using VBA in Office is a great way to generate code that can usually be converted/translated relatively easily into AHK's native COM calls. So I'm wondering if a similar statement can be made for C++ or VB or VBScript/ASP or one of the other three languages with respect to SDK calls generally speaking. Thanks, Joe
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Calling an SDK from AHK

23 Feb 2017, 03:23

If any of the examples (such as the VB and VBScript ones) use a COM based API, that would probably be the easiest to directly translate.

If it's a web based API (where an API call = a HTTP request), look for other scripts that use web based APIs, or just translate the VBScript examples, which most likely use the same COM objects as you'll find in AutoHotkey scripts.

For dll-based APIs, C#, VB and Delphi examples are often useful because the dll functions are defined in the code in a way similar to what DllCall needs. But if there's a VBScript example, there's no way it's dll-based. That's also unlikely for Java and PHP.
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

23 Feb 2017, 17:20

Thanks, lexicos, that's the kind of feedback I was looking for. Turns out that the SDK is publicly posted (so my NDA is not an issue):
https://www.inliteresearch.com/barcode- ... on-sdk.php

There are some examples underneath the blue buttons there, and more extensive ones here:
http://how-to.inliteresearch.com/barcode-reading-howto/

As you suggested, the VBScript one uses a COM based API. Here is an example from the site showing it:

Code: Select all

Sub ReadBarcode1D(fileName, page)
  On Error Resume Next
      'Create CiServer object:
  Set Ci = CreateObject("ClearImage.ClearImage")
      ' Create and configure reader
  Set reader = Ci.CreateBarcodePro
   If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub
  cibfCode39 = 2: cibfCode128 = 4:
  reader.Type = cibfCode39 + cibfCode128
    ' Open Image
  reader.Image.Open fileName, page
   If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub
    ' Read barcodes
  reader.Find 0
     If Err.Number <> 0 Then WScript.Echo Err.Description : Exit Sub
      ' Process results
  For Each Barcode In reader.Barcodes
     WScript.Echo Barcode.Text
  Next
End Sub
Any advice on translating just the COM code (I'm good with everything else) to AHK would be most appreciated. Thanks, Joe
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Calling an SDK from AHK

23 Feb 2017, 21:28

Just do basic VBScript to AutoHotkey translation. "The COM code" is just one function (CreateObject = ComObjCreate) and ordinary VBScript method and property calls.
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

23 Feb 2017, 23:56

CreateObject = ComObjCreate
Got that. What would reader.Image.Open fileName, page translate to?
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Calling an SDK from AHK

24 Feb 2017, 01:14

Code: Select all

reader.Image.Open(fileName, page)
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

24 Feb 2017, 06:35

Thanks, lexicos. One last thing:

Code: Select all

For Each Barcode In reader.Barcodes
  WScript.Echo Barcode.Text
Next
I don't care about the Echo statement (will make that an assignment statement, such as CurrentBarcode:=Barcode.Text), but how to translate the For-Next structure? Thanks again, Joe
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Calling an SDK from AHK

24 Feb 2017, 06:41

[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

24 Feb 2017, 13:07

Hi jNizM,

I read the doc — not for the first time, btw :) — but it is still eluding me. I guess you're saying that reader.Find 0 returns an object, with each element of the object being the value in a barcode that the barcode reader extracted. So if there are three barcodes on the Page fed to the function, three values (Barcode.Text) will be in the object. What's not clear to me is how I loop through the key-value pairs with the For statement.

Here's my translated code so far:

Code: Select all


ReadBarcode1D(FileName,Page)
{
  oClearImage:=ComObjCreate("ClearImage.ClearImage")
  If (ErrorLevel<>0)
  {
    MsgBox,4112,Fatal Error,Error Level %ErrorLevel% trying to create ClearImage object
    ExitApp
  }
  oReader:=oClearImage.CreateBarcodePro
  If (ErrorLevel<>0)
  {
    MsgBox,4112,Fatal Error,Error Level %ErrorLevel% trying to create barcode reader
    ExitApp
  }
  Code39:=2
  Code128:=4
  oReader.Type:=Code39+Code128 
  oReader.Image.Open(FileName,Page)
  If (ErrorLevel<>0)
  {
    MsgBox,4112,Fatal Error,Error Level %ErrorLevel% trying to open page %Page% from file:`n%FileName%
    ExitApp
  }
  oReader.Find(0)
  If (ErrorLevel<>0)
  {
    MsgBox,4112,Fatal Error,Error Level %ErrorLevel% trying to read barcodes
    ExitApp
  }
/*
  this is where I'm stuck...trying to translate this VBS For Each loop
  For Each Barcode In reader.Barcodes
    <code here to process Barcode.Text>
  Next
*/
  oReader.Close(0) ; just a guess
  oClearImage.Quit ; another guess
  Return
}
You can see above where I'm stuck. Thanks for any additional help. Regards, Joe
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

24 Feb 2017, 15:44

Additional efforts: I put in an IsObject debugging call for oClearImage, oReader, and oReader.Barcodes. Good news — all three came back as objects. I then tried this:

Code: Select all

BarcodeResults:=Object()
BarcodeResults[1]:=oReader.Barcodes
For BarcodeKey,BarcodeValue in BarcodeResults
{
  msgbox,4096,debug,key=%barcodekey%  val=%barcodevalue%
}
That comes back with key=1 but val= empty. The problem is likely that I'm not accessing Barcode.Text, which is surely where the barcode reader result is, as the VBS accesses it in the WScript.Echo line, but I don't know how to work Barcode.Text into the AHK For loop. Thanks for any help, Joe
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Calling an SDK from AHK

24 Feb 2017, 15:58

Try:

Code: Select all

For Barcode In reader.Barcodes
    MsgBox, % Barcode.Text
MS Office COM Basics section "5.2 Enumerating Collections" explains it a bit more.
User avatar
JoeWinograd
Posts: 2177
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Calling an SDK from AHK

24 Feb 2017, 16:23

Hi kon,
Thanks for jumping into this — your code is perfect! I tested it on a single image with four barcodes — the For loop came back with all four barcode values!

My thanks to everyone on this thread who helped. I now have a fully working translation of the VBS SDK in AHK. I'm extremely grateful! Regards, Joe

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 125 guests