Jump to content

About A struct Dll Callbacks

Recommended Posts

Hello friends,
I'm writing a code about DllCall a websocket.dll, its documentation looks like this:


void WebsocketOpen(const WebsocketCallbacks* callbacks, void* param)
This callback is triggered when a WebSocket is established. WebsocketCallbacks is defined as:

typedef void* WebSocketChannel;

typedef struct _WebsocketCallbacks {
    void (CALL_TYPE* OnWillConnect)(void* param, WebSocketChannel channel, const utf8* url);
    bool (CALL_TYPE* OnConnected)(void* param, WebSocketChannel channel);
    void (CALL_TYPE* OnReceive)(void* param, WebSocketChannel channel, int opCode, const char* buf, size_t len);
    void (CALL_TYPE* OnSend)(void* param, WebSocketChannel channel, int opCode, const char* buf, size_t len);
    void (CALL_TYPE* OnError)(void* param, WebSocketChannel channel);
} WebsocketCallbacks;

And I write to AutoIt like this:

Local $pParams = 0
Local $hWsOnWillConnect = DllCallbackRegister(OnWillConnectCallback, 'ptr', 'ptr;ptr;str')
Local $hWsOnConnected = DllCallbackRegister(OnConnectedCallback, 'bool', 'ptr;ptr')
Local $hWsOnReceive = DllCallbackRegister(OnReceiveCallback, 'ptr', 'ptr;ptr;int;ptr;int;bool')
Local $hWsOnSend = DllCallbackRegister(OnSendCallback, 'ptr', 'ptr;ptr;int;ptr;int;bool')
Local $hWsOnError = DllCallbackRegister(OnErrorCallback, 'ptr', 'ptr;ptr')
Local $tCallbackFuncs = DllStructCreate('ptr onWillConnect; ptr onConnected; ptr onReceive; ptr onSend; ptr onError')
$tCallbackFuncs.onWillConnect = DllCallbackGetPtr($hWsOnWillConnect)
$tCallbackFuncs.onConnected = DllCallbackGetPtr($hWsOnConnected)
$tCallbackFuncs.onReceive = DllCallbackGetPtr($hWsOnReceive)
$tCallbackFuncs.onSend = DllCallbackGetPtr($hWsOnSend)
$tCallbackFuncs.onError = DllCallbackGetPtr($hWsOnError)
Local $ret = DllCall('ws.dll', 'ptr', 'WebsocketOpen', 'ptr', DllStructGetPtr($tCallbackFuncs), 'ptr', $pParams)

Func OnWillConnectCallback($pParams, $WsChannel, $sURL)
    #forceref $pParams, $WsChannel, $sURL
    ConsoleWrite(1 & @CRLF)
Func OnConnectedCallback($pParams, $WsChannel)
    #forceref $pParams, $WsChannel
    ConsoleWrite(2 & @CRLF)
Func OnReceiveCallback($pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue)
    #forceref $pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue
    ConsoleWrite(3 & @CRLF)
Func OnSendCallback($pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue)
    #forceref $pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue
    ConsoleWrite(4 & @CRLF)
Func OnErrorCallback($pParams, $WsChannel)
    #forceref $pParams, $WsChannel
    ConsoleWrite(5 & @CRLF)

Can I ask if what I wrote above is correct or not?
Because I ran script and it only printed to console number 1 (means only ran the OnWillConnectCallback function)

Thank you for reading my question. (Sorry my english is not very good)

Edited by NewCommer
Link to comment
Share on other sites

Hi, Where can I see library's Documentation? is a free library?



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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...