Sign in to follow this  
Followers 0
Andreik

BINK_STRUCT

7 posts in this topic

#1 ·  Posted (edited)

Can someone put me on the right way with this code? I want to open a bink file to play it as intro for a game but I am not sure about bink functions [binkw32.dll]. I found this code but is C and I am not sure about return of BinkOpen function in AutoIt.

typedef signed char     s8; 
typedef unsigned char   u8; 
typedef signed int      s32; 
typedef unsigned int    u32; 
typedef signed short    s16; 
typedef unsigned short  u16; 

typedef struct 
{ 
    s32 Width;          // frame height 
    s32 Height;         // frame width 
    s32 Frames;         // total number of frames in movie 
    s32 FrameNum;       // current frame 
    s32 LastFrame; 
    s32 FpsMul;         // frames/second multiplier 
    s32 FpsDiv;         // frames/second divisor 
    s32 Unknown0;       // Unknown 
    u32 Flags; 
    u8 Unknown1[260]; 
    s32 CurPlane;       // current plane 
    void *Plane0;       // pointer to plane 0 
    void *Plane1;       // pointer to plane 1 
    u8 Unknown2[8]; 
    s32 yWidth;         // Y plane width 
    s32 yHeight;        // Y plane height 
    s32 uvWidth;        // U&V plane width 
    s32 uvHeight;       // U&V plane height 
} BINK_STRUCT, *HBINK; 

/* 
HBINK BinkOpen(HANDLE, u32): 
 
    BinkOpen opens and initializes a Bink file for playback. 
 
    hBinkFile: A Windows file HANDLE that refers to the Bink file to be read. 
 
    dwFlags: The meaning of all the flags is unclear, but MPC calls BinkOpen  
    with 0x00800000. 
 
    Returns: On success returns a pointer to a BINK_STRUCT that will be used for playing the Bink  
    file, else return is zero 
*/ 
HBINK BinkOpen(HANDLE hBinkFile, u32 dwFlags);

#include <Array.au3>
#include <WinAPI.au3>

$FILE = _WinAPI_CreateFile("LOGO.bik", 2, 2)
;_BinkOpen@8 is the original name in dll
$RESULT = DllCall("binkw32.dll","ptr","_BinkOpen@8","hwnd",$FILE,"uint",0x00800000)
If @error Then
    MsgBox(0,"ERROR",@error)
Else
    _ArrayDisplay($RESULT)
EndIf
_WinAPI_CloseHandle($FILE)

If I run this code the results array looks like:

[0]|0x031C1B00

[1]|0x000002C4

[2]|8388608

but the script finish fast and give me a fatal error AutoIT3.exe ended.rc:-1073741819

Any idea how to get there HBINK struct as result?

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites



The function will return a pointer to the struct, you need to use the second parameter of DLLStructCreate().

Share this post


Link to post
Share on other sites

I don't have time to create the struct because my script crush very fast after call this dll: AutoIT3.exe ended.rc:-1073741819


When the words fail... music speaks

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I don't have time to create the struct because my script crush very fast after call this dll: AutoIT3.exe ended.rc:-1073741819

Then you're probably calling the function with a wrong number or type of parameters. I'll see if I can find a copy of binkw32.dll from a game and try it out.

EDIT: Done it, and the following script seems to work (place binkw32.dll and a test video named bink_test.bik on its folder).

; #INDEX# =======================================================================================================================
; Title .........: _DLLStruct Array Conversion Functions
; Description ...: Provides facilities to conver DLLStructs to arrays. Useful for debugging or displaying.
; Author ........: Daniel Miranda (danielkza)
; ===============================================================================================================================

; #FUNCTION# ====================================================================================================================
; Name...........: _DLLStructToArray
; Description ...: Traverses a DLLStruct, and return it's data as an array
; Syntax.........: _DLLStructToArray(Const ByRef $hStruct)
; Parameters ....: $hStruct     - DLLStruct handle
; Return values .: Success      - Array containing the data
;                  Failure      - 0
; Author ........: Daniel Miranda (danielkza)
; Modified.......:
; Remarks .......: There is no implicit or explicit conversion of types, AutoIt takes care of it all.
;                  Check DLLStructCreate for more info and a conversion table.
;
;                  Failure reading any of the elements is not accepted. In this case none of them will be returned, and @error will be set to 3 (check below).
;
;                  Arrays in the structure are processed correctly, but in 'PHP style' (assigning arrays to array elements).
;                  _ArrayDisplay does NOT handle that, so you must do it manually.
;
;                  @error values:
;                      == 1: invalid DLLStruct
;                      == 2: empty DLLStruct
;                      == 3: error reading one of the elements. @extended contains the index where the failure occured
; Related .......: DLLStructCreate, DLLStructGetData, _DLLStructElementToArray
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _DLLStructToArray(Const ByRef $hStruct)
    IF NOT IsDLLStruct($hStruct) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $aData[17], $iCount=0, $iSize=16
    Local $temp, $iError=0

    While True
        $iCount+=1
        $temp = DllStructGetData($hStruct, $iCount)

        $iError = @error
        Switch $iError
            Case 2
                $iCount-=1
                ExitLoop
            Case 1, 4
                Return SetError(3, $iCount, 0)
        EndSwitch

        If $iCount > $iSize Then
            $iSize *= 2
            ReDim $aData[$iSize+1]
        EndIf

        Switch $iError
            Case 0
                $aData[$iCount] = $temp
            Case 5
                $aData[$iCount] = _DLLStructElementToArray($hStruct, $iCount)
                If @error Then Return SetError(3, $iCount, 0)
            Case Else
                Return SetError(3, $iCount, 0)
        EndSwitch
    WEnd

    If $iCount < 1 Then Return SetError(2, 0, 0)
    ReDim $aData[$iCount+1]
    $aData[0] = $iCount

    Return $aData
EndFunc

; #FUNCTION# ====================================================================================================================
; Name...........: _DLLStructElementToArray
; Description ...: Traverses a single DLLStruct element, and return it's data as an array
; Syntax.........: _DLLStructElementToArray(Const ByRef $hStruct, Const $iElement)
; Parameters ....: $hStruct     - DLLStruct handle
;                  $iElement    - Index of the element to retrieve
; Return values .: Success      - Array containing the data
;                  Failure      - 0
; Author ........: Daniel Miranda (danielkza)
; Modified.......:
; Remarks .......: Check _DLLStructToArray for a version that reads the whole structure.
;                  As _DLLStructToArray, no type conversion is performed, and error(s) cause the whole function to fail.
;
;                  @error values:
;                      == 1: invalid DLLStruct
;                      == 2: empty DLLStruct
;                      == 3: error reading one of the elements. @extended contains the index where the failure occured.
; Related .......: _DLLStructToArray, DLLStructCreate, DLLStructGetData
; Link ..........;
; Example .......;
; ===============================================================================================================================
Func _DLLStructElementToArray(Const ByRef $hStruct, Const $iElement)
    If NOT IsDLLStruct($hStruct) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $aData[17], $iSize=16, $iCount=0
    Local $temp

    While True
        $iCount+=1
        $temp = DLLStructGetData($hStruct, $iElement, $iCount)
        Switch @error
            Case 0
                IF $iCount > $iSize Then
                    $iSize*=2
                    Redim $aData[$iSize+1]
                EndIf
                $aData[$iCount]=$temp
            Case 3
                ExitLoop
            Case Else
                Return SetError(3, $iCount, 0)
        EndSwitch
    WEnd

    IF $iCount < 1 Then Return SetError(2, 0, 0)
    ReDim $aData[$iCount]

    Return $aData
EndFunc

#include <WinAPI.au3>
#include <Array.au3>


Global Const $tagBINK_STRUCT = _
    "int Width; int Height; int Frames; int FrameNum; int LastFrame;" & _
    "int FpsMul; int FpsDiv; int Unknown0; uint Flags; byte Unknown1[260];" & _
    "int CurPlane; ptr Plane0; ptr Plane1; byte Unknown2[8];" & _
    "int yWidth; int yHeight; int uvWidth; int uvHeight;"

Global $binkw32 = DllOpen("binkw32.dll")
If @error Then Exit

Global $hFile = _WinAPI_CreateFile("bink_test.bik", 2, 2)
If @error Then Exit

Global $Result = DllCall($binkw32, "ptr", "_BinkOpen@8", _
    "handle", $hFile, _
    "uint",   0x00800000 _
)

_ArrayDisplay($Result)
Global $BINK_STRUCT = DllStructCreate($tagBINK_STRUCT, $Result[0])
Global $BinkArray = _DLLStructToArray($BINK_STRUCT)
_ArrayDisplay($BinkArray)
Edited by danielkza

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

In this case I should get @error 4 not results from array. Anyway you can download this dll from here.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I updated my last post, see if it is of any help.

Edited by danielkza

Share this post


Link to post
Share on other sites

It works, thank you. Now I need to take a closer look to see what you do there. :)


When the words fail... music speaks

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