Sign in to follow this  
Followers 0
Wena

Can not get return code from DLL

18 posts in this topic

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

Share this post


Link to post
Share on other sites



Hi,

The DllCall function returns an array (see helpfile).

So it's not e.g $POS, but $POS[0] for the return value.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Hi

Thanks for the quick reply

I am getting "send dont send errors" now. Are there include files that I need to add?

BR

Wena

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

I think the right way is struct* and not ptr


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Please attach your Dll or PM me and I'll try to have a successful dllcall.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Have you tried issuing the DllCall command using "byte *" instead of "ptr"?

$POS = DllCall($dopen, "int", "KeylockScanPosition", "int", 1, "byte *", DllStructGetPtr($nKeyData))

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

byte* does not exist (in autoit), it's struct*

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

You may be correct. However, the help file shows BYTE as a valid type, so I figured byte* would work.

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