Jump to content

DllCall - Unsure of how to access DLL file


Go to solution Solved by funkey,

Recommended Posts

Hi,

This is my first time attempting to access a DLL file via AutoIT, but I just keep crashing the script editor (presumably because I'm doing something wrong...)

My code is-

$fOpen = DllOpen ("jeti_core.dll")
If $fOpen = -1 Then
    MsgBox(0,"Warning!","DLL File Not Found")
Else
    DllCall($fOpen,"DWORD",1,"DWORD",0)
    $sTest = DllCall($fOpen,"DWORD",13,"hwnd",1)
    MsgBox(0,"",$sTest)

EndIf
DllClose("jeti_core.dll") 

Now I'm confident it doesn't work as I have no idea that it is correct, I've had a good search and checked the manual, but from what I see, I'm just not sure how to achieve this.

What I'm trying to achieve above it to turn a laser light on in a light calibration unit, which can be accessed through Ordinal #13 (#1 should open the first device).  I've attached the part of the manual that relates to this part.

Can anyone give me a gentle push in the right direction?

Many thanks

 

post-85850-0-42741400-1420557668_thumb.j

Link to comment
Share on other sites

DllCall($fOpen,"DWORD", "jeti_setlaserstat", "DWORD", 1, "BOOL", 0)

Probably a bit more like that from the image you post.

Also return from dllcall is an array, please read the helpfile again.

Edited by JohnOne

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Final question;

Screenshot attached shows open device, which has dwDevice called by reference, I have to connect first then turn the laser on or off - how do I deal with the reference?  Doing some testing I've found that I'm usually not connecting for one and keep ending up with an invalid handle error (using hex to get the code)

post-85850-0-85654300-1420562076_thumb.j

Link to comment
Share on other sites

$Ret=DllCall($fOpen,"DWORD", "JETI_OpenDevice", "dword", 0, "dword*", 0)
$hDevice=$Ret[2]

Saludos

Link to comment
Share on other sites

$DLL = DllOpen("jeti_core.dll")
$conn = DllCall($DLL,"DWORD", "JETI_OpenDevice", "DWORD", 0, "DWORD", 0)
$Test = DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", 0, "BOOL", 1)
MsgBox(0,"",Hex($Test[0]))

Running that results in 0000000000000015 which checking in the SDK manual gives me an error of "invalid device handle".

Sorry if I'm being thick, uncharted territory for me!

Link to comment
Share on other sites

Thanks - I understand how the asterisk now integrates with this (also found a handy PDF quick guide and followed that example).

The code I now have is

$DLL = DllOpen("jeti_core.dll")

Local $Ret
Local $hDevice
Local $Close
Local $cDevice

; Open Device #0
$Ret = DllCall($DLL,"DWORD", "JETI_OpenDevice", "DWORD", "0", "DWORD*", $hDevice)
$hDevice = $Ret[1]

; Set laser BOOL = 1
DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", $hDevice, "BOOL", 1)

; Close Device
$Close = DllCall($DLL,"DWORD", "JETI_CloseDevice", "DWORD", $hDevice)
$cDevice = $Close[1]

; $hDevice gives us 0000000000000000 code which according to Jeti manual = JETI_SUCCESS
MsgBox(0,"",Hex($hDevice))

But still doesn't turn the laser on -- have I got this right?

Was making good progress using the MsgBox to show what error codes I ended up with - what I have here seems to return sucess from open and close.

Edited by hyperjase
Link to comment
Share on other sites

try to pass the index without put "0" just use 0. (lol I don't remember how to write "" in english)

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

I've gone a little more specific with targeting the unit, namely selecting the COM port (3) and baud rate (9600).

Here is the current code:

$DLL = DllOpen("jeti_core.dll")

Local $Ret
Local $hDevice
Local $Close
Local $cDevice

; Open Device #0
$Ret = DllCall($DLL,"DWORD", "JETI_OpenCOMDevice", "DWORD", "3", "DWORD", "9600", "DWORD*", $hDevice)
$hDevice = $Ret[3]

; Set laser BOOL = 1
DllCall($DLL,"DWORD", "JETI_SetLaserStat", "DWORD", $hDevice, "BOOL", 1)

; Close Device
$Close = DllCall($DLL,"DWORD", "JETI_CloseDevice", "DWORD", $hDevice)
$cDevice = $Close[1]

; $hDevice gives us 0000000000000000 code which according to Jeti manual = JETI_SUCCESS
MsgBox(0,"",Hex($hDevice))

The one thing I'm curious about is $hDevice become the handle?  As I find I keep getting 0000000000000015 codes which are "JETI_INVALID_HANDLE"

Link to comment
Share on other sites

Link to comment
Share on other sites

Try...

$DLL = DllOpen("jeti_core.dll")

$STRUCT = DllStructCreate("DWORD")

$CALL = DllCall($DLL, "DWORD", "JETI_GetNumDevices", "DWORD*", DllStructGetPtr($STRUCT))

If Not $CALL[0] Then

    MsgBox(0, "Num:", DllStructGetData($STRUCT, 1))
    DllClose($DLL)
    Exit
        
EndIf

DllClose($DLL)
MsgBox(0, "Num:", "Error")
Edited by JohnOne

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

Monkey's are, like, natures humans.

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