Sign in to follow this  
Followers 0
chachew

DllCall() question with scanner function

24 posts in this topic

#1 ·  Posted (edited)

Ok, so this is my first attempt at DllCall(), other than the HelpFile example. I have a DLL im trying to read for some hardware that i use.

For the DllCall("dll", ...,....) can i put the full path to the dll if its not located in the sys32 folder?

Below is the documentation for that particular function, which i find with DLL Export viewer. I am uncertain what im suppose to be using for the "return type" - "function" - "parameters"

Any help would be appreciated. I have DllCall("C:\Program Files (x86)\ScanX.dll", "dword", "_CSSNLib::ScanToFileEx") but that is obviously not working for me.

ScanToFileEx

Format

ScanToFileEx(fileName As String) As Long

Parameters

[in] fileName – Null terminated string that holds destination bitmap file name.

Return Value

If function succeeds, the return value is SLIB_ERR_NONE

If function fails, the return number is may be one of the following:

LICENSE_INVALID – Library was not initialized with proper license.

SLIB_ERR_SCANNER_NOT_FOUND – No attached scanner was found.

SLIB_ERR_SCANNER_GENERAL_FAIL

SLIB_ERR_SCANNER_NOT_FOUND

SLIB_ERR_HARDWARE_ERROR

SLIB_ERR_PAPER_FED_ERROR

SLIB_ERR_SCANABORT

SLIB_ERR_NO_PAPER

SLIB_ERR_PAPER_JAM

SLIB_ERR_FILE_IO_ERROR

SLIB_ERR_PRINTER_PORT_USED

SLIB_ERR_OUT_OF_MEMORY

Description

This function works identically to ScanBmpFile, and in addition, the function displays a modal

progress bar while the scan is in progress.

Edited by chachew

Share this post


Link to post
Share on other sites



I'm no DllCall whizzkid but at a guess (just to give you a rough Idea)

Yes you can define the path to dll, but maybe it needs registering

"ScanToFileEx(fileName As String) As Long" suggets the return type of the function is a Long, which could translate as int if you wish in AutoIt.

It also suggests that it takes just one parameter ,a string which is the path to a bitmap filename.

Its also possible (without full docs) that its in parameter could also be its out parameter (by ref) and is actually working on the file you provide.

Don't take this as true, like I say It's an educated guess.

DllCall("C:\Program Files (x86)\ScanX.dll", "long", "_CSSNLib::ScanToFileEx","str","c:\path\to\bitmap.bmp")

Infact I highly doubt that is correct, as it looks like the function is within a class and you may need to use it as an object type

I've rambled enough.

I'm out.


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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the info, If i do

$dll=DllOpen("C:\Program Files (x86)\ScanX.dll")

MsgBox(0,"ScanToFileEX", $dll)

I get a result of -1 back so it looks like it doesnt even open the DLL. I've tried to register the DLL first but i get the same response back from $dll

Seems like the DLL is locked or something? Is that possible? I have tried to register, Unregister, move it to different locations and i get -1 every time. If i try a completely different DLL i get a return of 1

EDIT: Ok, i have found in another thread that its because my 64bit machine trying to access a 32bit DLL. Added #AutoIt3Wrapper_UseX64=n to the script and now i do not get an error any longer. Now i just need to figure out how to access the DLL with the correct parameters and things

Edited by chachew

Share this post


Link to post
Share on other sites

http://www.id-reader.com/ftp/applications/sdk/docs/ScanX.pdf Is the documentation file for the DLL im trying to use. It states "ScanX.Dll library is a wrapper ActiveX object that eases the integration between VC++ source libraries and VB Script \ VB code."

Does this mean that i have to write some ActiveX code for this to function?

Share this post


Link to post
Share on other sites

Yes, something like that.

I've seen plenty of examples of this around the forums I just cannot remember where.

Its along the lines of registering the dll successfully then something like

$oOBJ = ObjCreate("scanx")

$oOBJ.ScanToFileEX("path")


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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

How exactly do i get all the necessary "return types" of various DLL variables that i am trying to access? Is that something that the DLL documentation should outline?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Crap...i hoped it would be a little easier than that to make this work.

So is all the work being done by DllCall? Like in this example "DllCall("user32.dll","int","MessageBoxW","hwnd",0,"wstr","Hello from Dll tutorial!","wstr","Info","uint",0)"

I assume ObjCreate is just an easy way to create a reference to that same function for future calls from ObjGet?

Edited by chachew

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

#AutoIt3Wrapper_UseX64=n
$dll=DllOpen("C:\Program Files (x86)\ScanX.dll")
$result=DllCall($dll, "none", "_CSSNLib::CalibrateScanner")
MsgBox(0,"ScanToFile", @error)

The @error reads as 3 - "function" not found in the DLL file

Edited by chachew

Share this post


Link to post
Share on other sites

When i call the function name with the ordinal value, SciTE crashes :D

Share this post


Link to post
Share on other sites

This is about as far as i can get

Global $oErrorHandler = ObjEvent("AutoIt.Error","ObjErrorHandler")
$oOBJ=ObjCreate("ScanX.CSSNLib")
$oOBJ.InitSlibLibrary("blah blah blah")
$oOBJ.CalibrateScanner()
Func ObjErrorHandler()
    ConsoleWrite("A COM Error has occured!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _
            "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _
            "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _
            )
EndFunc

Share this post


Link to post
Share on other sites

Looks like you are making good progress to me, and the results are?

Errors out..

: ==> The requested action with this object has failed.:
$oOBJ.InitSlibLibrary("blah blah blah")
$oOBJ.InitSlibLibrary("blah blah blah")^ ERROR
->15:49:54 AutoIT3.exe ended.rc:1

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

You might want to check your PC for available objects, it might give you an idea about the syntax, or at least its name.

Once again (and I know I'm not much use to you here) but there is an app you can use for that, I tried it after reading a post here

Might be ole viewer or something and might even be sitting on your system.

EDIT:

Did you successfully register the dll file?

If not you are flogging a dead horse, unless of course its already registered by software installed.

Edited by JohnOne

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

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

The file IS registered by an app plus i have manually registered it to make sure that was not the problem. I feel like im missing something in the file to make it work. /frustrating

Share this post


Link to post
Share on other sites

OK, i finally got it to work. I found out that the driver for the scanner i was using was not working correctly. Reinstalled the drivers and now the DLL function is working as expected! :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0