Calling an SDK from AHK
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Calling an SDK from AHK
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
Re: Calling an SDK from AHK
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.
It might be helpful if you can share a link to the SDK and/or it's documentation.
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
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
Re: Calling an SDK from AHK
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.
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.
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
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:
Any advice on translating just the COM code (I'm good with everything else) to AHK would be most appreciated. Thanks, Joe
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
Re: Calling an SDK from AHK
Just do basic VBScript to AutoHotkey translation. "The COM code" is just one function (CreateObject = ComObjCreate) and ordinary VBScript method and property calls.
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
Got that. What would reader.Image.Open fileName, page translate to?CreateObject = ComObjCreate
Re: Calling an SDK from AHK
Code: Select all
reader.Image.Open(fileName, page)
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
Thanks, lexicos. One last thing:
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
Code: Select all
For Each Barcode In reader.Barcodes
WScript.Echo Barcode.Text
Next
Re: Calling an SDK from AHK
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
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:
You can see above where I'm stuck. Thanks for any additional help. Regards, Joe
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
}
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
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:
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
Code: Select all
BarcodeResults:=Object()
BarcodeResults[1]:=oReader.Barcodes
For BarcodeKey,BarcodeValue in BarcodeResults
{
msgbox,4096,debug,key=%barcodekey% val=%barcodevalue%
}
Re: Calling an SDK from AHK
Try:
MS Office COM Basics section "5.2 Enumerating Collections" explains it a bit more.
Code: Select all
For Barcode In reader.Barcodes
MsgBox, % Barcode.Text
- JoeWinograd
- Posts: 2177
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Calling an SDK from AHK
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
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
Who is online
Users browsing this forum: No registered users and 125 guests