Jump to content

Can not get return code from DLL


Wena
 Share

Recommended Posts

Hi All

I am trying to read a DLL but I am not getting a return code.

It is supposed to return the KEYLOCK position on a Tipro POS keyboard.

Below is from the CHM of the Tipro software:

KeylockScanPosition

Syntax int KeylockScanPosition (int nKeylockNum, unsigned char *nKeyData);

 

Below is my code:

$dlll = DllOpen("C:\Windows\System32\WKMidApi.dll")
$POS = DllCall($dlll, "int","KeylockScanPosition")

MsgBox(0,"pos","POS=" & $POS & " " & "error=" & @error)
DllClose($dlll)

(I am by no means a programmer and normally use Autoit for basic needs.)

Kind Regards

Wena

Link to comment
Share on other sites

Hi

I think this is over my head.

I have read and reread the help file and I am getting no where.

I added some parameters( purely guess work as I have no idea what parameters to use) and at least the "send don't send has gone".

I am getting error 11 which is "API function parameter refers to non existing module".

I will google some more to learn about this.

Thanks for all the help.

Alistair

Link to comment
Share on other sites

Hi

Below is the rest of the page.

*******

Parameter

Description

nKeylockNum

Keylock module reference number looking from the left side of the configuration.

nKeyData

Current keylock position number.

 

Remark Scans keylock and returns current keylock position number.

 

*******

It also has sample code, below is a vbscript supplied:

****

Public Declare Function KeylockScanPosition Lib "WKMidApi" (ByVal nKeyLockNum As Integer, _
                                                           ByRef nKeyData As Byte) As Integer
'/* Scans keylock and returns current keylock position.                      */
'/* arguments (IN)  : selected Keylock module number                         */
'/* arguments (OUT) : current keylock position number                        */
'/* return value    : command status : 0 == OK, else error code              */

 

*******

KR

Alistair

Link to comment
Share on other sites

Function should probably look more like this...

Func _KeylockScanPosition($nKeylockNum)
    ;$nKeyData = DllStructCreate('byte') ; test 1
    $nKeyData = DllStructCreate('byte[1]') ; test 2
    $POS = DllCall("WKMidApi.dll", "int", "KeylockScanPosition", 'int', $nKeylockNum, 'ptr', DllStructGetPtr($nKeyData))
    $Error = @error
    ConsoleWrite('DllCall @error state -: ' & $Error & @LF)

    If Not $Error Then
        ;Return DllStructGetData($nKeyData, 1) ; test 1
        Return DllStructGetData($nKeyData, 1, 1); test 2
    EndIf

    Return SetError(1, 0, 0)
EndFunc   ;==>_KeylockScanPosition

Although I have no Idea what nKeyLockNum actually is, but you definately need to know that, and pass it.

EDIT:

It may also be the case that you just pass $nKeyData rather than a pointer to it. So you might also try removing DllStructGetPtr().

EDIT2:

It is also possible that the out param is infact of int size and wants a byte array of 'byte[4]'.

I'd also just try passing struct of 'int'

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

Hi Guys

I am not ignoring your posts and suggestions.

I am busy testing some of the examples given.

I had to remove the func as it (for some reason) when run it ignored it. I tested this with a message box before and after func.

I have got a little further, I am now getting a hex code return but an error "11" which is "API function parameter refers to non existing module".

I also have found out that the first parameter is "int, 1

Regards

Wena

Link to comment
Share on other sites

Hi

I put comments in of what is happenning.

If FileExists("c:\windows\system32\WKMidApi.dll") Then
        $nKeyData = DllStructCreate("char[7]") ; test 2
        $dopen = DllOpen("c:\windows\system32\WKMidApi.dll")
        $POS = DllCall($dopen, "int", "KeylockScanPosition", "int", 1, "ptr", DllStructGetPtr($nKeyData)) ;I am sure the ptr should be an unassigned char "UChar" but nothing in the help file about this.
        $data = DllStructGetData($nKeyData, 1, 1)
        MsgBox(0, "pos", $POS[0]) ;get return of 11
        MsgBox(0, "pos", $POS[1]) ;get return of 1
        MsgBox(0, "pos", $POS[2]) ;get return of hex number (changes after each compile)
        DllClose($dopen)
    Else
        MsgBox(0, "Notexists", "Notexists")
    EndIf

KR

Alistair

Link to comment
Share on other sites

I believe that char is used for uchar, you could probably use also byte or booloean for uchar.

Without knowing exactly what this library is for or does it's difficult to know what's going on.

Maybe you have a link to somewhere to see how this call is used practically in code.

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