Jump to content

dllcall


elawady
 Share

Recommended Posts

#include <WinAPI.au3>

Local $aTest

For $i = 0 To 9
    $aTest = _capGetDriverDescription($i)
    If @error Then ExitLoop
    ConsoleWrite($aTest[0] & @TAB & $aTest[1] & @CRLF)
Next


Func _capGetDriverDescription($iIndex)
    Local $tBuffName, $tBuffVer
    Local $aResult, $aRet[2]
    
    $tBuffName = DllStructCreate("char[128]")
    $tBuffVer  = DllStructCreate("char[128]")
    
    $aResult = DllCall("avicap32.dll", "int", "capGetDriverDescriptionA", "ushort", $iIndex, "ptr", DllStructGetPtr($tBuffName), _
                        "int", 128, "ptr", DllStructGetPtr($tBuffVer), "int", 128)
                        
    If @error Then Return SetError(@error, @extended, 0)
    
    If $aResult[0] Then
        $aRet[0] = DllStructGetData($tBuffName, 1)
        $aRet[1] = DllStructGetData($tBuffVer, 1)
        Return $aRet
    EndIf
    
    Return SetError(1, 0, 0)
EndFunc

Don't know if it's working because I have no capturing driver.

Link to comment
Share on other sites

I would call it this way (based on example of Authenticity):

Global $aTest

For $i = 0 To 9
    $aTest = _capGetDriverDescription($i)
    If @error Then ExitLoop
    ConsoleWrite($aTest[0] & @TAB & $aTest[1] & @CRLF)
Next


Func _capGetDriverDescription($iDriverIndex)

    Local $aCall = DllCall("avicap32.dll", "int", "capGetDriverDescriptionW", _
            "ushort", $iDriverIndex, _
            "wstr", "", _
            "int", 1024, _
            "wstr", "", _
            "int", 1024)

    If @error Or Not $aCall[0] Then
        Return SetError(1, 0, 0)
    EndIf

    Local $aRet[2] = [$aCall[2], $aCall[4]]

    Return $aRet

EndFunc
Link to comment
Share on other sites

Hi, I am in a similar situation. I am trying to call a DLL called CASRNF32.dll with instruction GetCasVersion. However in the DLL data sheet I found this:

"Prior to calling any function of the CASCON DLL, call function

InitCasRunF supplying a pointer/ a handle aCas It must be

assigned to each function. Call DoneCasRunF as last function

before ending the application or before unloading the CASCON

DLL.."

Any help would be appreciated,

Thanks

Link to comment
Share on other sites

I have copied some of the information (usage, syntax) from the DLL manual and placed it in a word doc. It has lost some of the formatting (makes it harder to read) but hopefully it is sufficient. If someone could just help me get started I'd appreciate it. Maybe using the function "GetCasVersion" for starters.

casrnf_dll.doc

Link to comment
Share on other sites

; Function: _InitCasRunF
; OUT: $pCas
; Return: $sMsg from function. Success set @error to 0, error set @error to 1.
; Example: $sMsg = _InitCasRunF(DllStructGetPtr($tCAS), 0, 0, 0, 0, 0)
Func _InitCasRunF($pCas, $sCmdLine, $pMainData, $pCheckBreakProc, $pReadKeyProc, $pMsgBoxProc)
    Local $tMsg = DllStructCreate("char[256]")
    Local $aResult = DllCall("CASRNF32.dll", "int", "InitCasRunF", _
                                             "ptr", $pCas, _
                                             "str", $sCmdLine, _
                                             "ptr", $pMainData, _
                                             "ptr", $pCheckBreakProc, _
                                             "ptr", $pReadKeyProc, _
                                             "ptr", $pMsgBoxProc, _
                                             "ptr", DllStructGetPtr($tMsg)
                                             
    If @error Or $aResult[0] <> 0 Then Return SetError(1, 0, DllStructGetData($tMsg, 1)) ; If casOk = 0 then check if return value is not ok, else check casOk's value.
    Return SetError(0, 0, DllStructGetData($tMsg, 1))
EndFunc


; Function: _GetCasVersion
; Return: $sMsg from function. Success set @error to 0, error: set @error to 1.
; Example: $sMsg = _GetCasVersion()
Func _GetCasVersion()
    Local $tMsg = DllStructCreate("char[256]")
    Local $aResult = DllCall("CASRNF32.dll", "int", "GetCasVersion", "ptr", DllStructGetPtr($tMsg))
                                             
    If @error Or $aResult[0] <> 0 Then Return SetError(1, 0, DllStructGetData($tMsg, 1)) ; If casOk = 0 then check if return value is not ok, else check casOk's value.
    Return SetError(0, 0, DllStructGetData($tMsg, 1))
EndFunc

If the calling convention is not __stdcall it's probably __cdecl so the functions return value in DllCall() is "value:cdecl" for example:

DllCall("CASRNF32.dll", "int:cdecl", "GetCasVersion", "ptr", DllStructGetPtr($tMsg))

The arguments that specify callback procedures in _InitCasRunF() should be in the expected format the library is expecting and can be sent to the function like:

Local $hMsgBoxProc = DllCallbackRegister("_MsgBoxProc", "int", "ptr;str;int") ; If calling convention is cdecl then it's "int:cdecl", I guess.
_InitCasRunF(DllStructGetPtr($tCAS), 0, 0, 0, 0, DllCallbackGetPtr($hMsgBoxProc)) ; According to the documentation, you must supply an abstract +
                                                                                  ; pointer to this function. It might be that you can supply 0 +
                                                                                  ; and that the $pMainData in the callback function will be +
                                                                                  ; null also but don't count on it.

; ...

Func _MsgBoxProc($pMainData, $sMessage, $iFlags)
    Local $tMsg = DllStructCreate("char[256]", $sMessage)
    
    Return MsgBox($iFlags, "Error", DllStructGetData($tMsg, 1))
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

Hello Authenticity,

I have been trying to make the sample script you gave me work with little success. I am able to call _GetCasVersion() and that does return the DLL version. However I get a windows error "Autoit.exe has generated errors and will be closed by window" when calling _InitCasRunF(). I have messed around with the example you gave but seem to get no where. I was wondering if you or anyone else may have some insight?

Thanks

Link to comment
Share on other sites

Do you have the definition of the tCascon structure? If so can you post how HCASCON is defined? i.e. is it a pointer to a structure or just a void pointer? Try this one:

Func _InitCasRunF(ByRef $hCas, $sCmdLine = 0, $pMainData = 0, $pCheckBreakProc = 0, $pReadKeyProc = 0, $pMsgBoxProc = 0)
    Local $tMsg = DllStructCreate("char[256]")
    Local $aResult = DllCall("CASRNF32.dll", "int", "InitCasRunF", _
                                             "int*", 0, _
                                             "str", $sCmdLine, _
                                             "ptr", $pMainData, _
                                             "ptr", $pCheckBreakProc, _
                                             "ptr", $pReadKeyProc, _
                                             "ptr", $pMsgBoxProc, _
                                             "ptr", DllStructGetPtr($tMsg)
                                             
    If @error Or $aResult[0] <> 0 Then Return SetError(1, 0, DllStructGetData($tMsg, 1)) ; If casOk = 0 then check if return value is not ok, else check casOk's value.
    $hCas = $aResult[1]
    Return SetError(0, 0, DllStructGetData($tMsg, 1))
EndFunc

and call it like:

Local $hCas
Local $iRes = _InitCasRunF($hCas)
; Check the return value and the @error macro value for failure.

If the calling convention is __cdecl the function should be:

Func _InitCasRunF(ByRef $hCas, $sCmdLine = 0, $pMainData = 0, $pCheckBreakProc = 0, $pReadKeyProc = 0, $pMsgBoxProc = 0)
    Local $tMsg = DllStructCreate("char[256]")
    Local $aResult = DllCall("CASRNF32.dll", "int:cdecl", "InitCasRunF", _
                                             "int*", 0, _
                                             "str", $sCmdLine, _
                                             "ptr", $pMainData, _
                                             "ptr", $pCheckBreakProc, _
                                             "ptr", $pReadKeyProc, _
                                             "ptr", $pMsgBoxProc, _
                                             "ptr", DllStructGetPtr($tMsg)
                                             
    If @error Or $aResult[0] <> 0 Then Return SetError(1, 0, DllStructGetData($tMsg, 1)) ; If casOk = 0 then check if return value is not ok, else check casOk's value.
    $hCas = $aResult[1]
    Return SetError(0, 0, DllStructGetData($tMsg, 1))
EndFunc
Link to comment
Share on other sites

4.3 Data Types

Used data types are 32-bit values, byte arrays, and tCascon - an

abstract structure for the application.

PASCAL

type

pCascon = ^tCascon;

tCascon = Record

Sys : pointer;

end;

C/C++

#define HCASCON long int

Calling InitCasRunF function will provide a pointer to such a

structure. Then this pointer/ this handle has to be provided as

parameter for every other function.

Link to comment
Share on other sites

PASCAL? They give the first example of implementation in PASCAL?

Might as well be Summarian on a clay tablet!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The windows error no longer occurs but the script seems to hang indefinitely when the dll is called. I had to stop the script execution.

Who ever wrote this application is fond of Pascal, they created another language called CASLAN based on PASCAL.

Link to comment
Share on other sites

Hi, I am in a similar situation. I am trying to call a DLL called CASRNF32.dll with instruction GetCasVersion. However in the DLL data sheet I found this:

"Prior to calling any function of the CASCON DLL, call function

InitCasRunF supplying a pointer/ a handle aCas It must be

assigned to each function. Call DoneCasRunF as last function

before ending the application or before unloading the CASCON

DLL.."

Any help would be appreciated,

Thanks

It would seem that you would need to DLLOpen(), InitCasRunF(), Do Stuff, DoneCasRunF(), DLLClose().

Lar.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

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