NewCommer Posted November 5, 2021 Share Posted November 5, 2021 (edited) Hello friends, I'm writing a code about DllCall a websocket.dll, its documentation looks like this: Quote 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) EndFunc Func OnConnectedCallback($pParams, $WsChannel) #forceref $pParams, $WsChannel ConsoleWrite(2 & @CRLF) EndFunc Func OnReceiveCallback($pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue) #forceref $pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue ConsoleWrite(3 & @CRLF) EndFunc Func OnSendCallback($pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue) #forceref $pParams, $WsChannel, $opCode, $pBuffer, $LenghtBuffer, $IsContinue ConsoleWrite(4 & @CRLF) EndFunc Func OnErrorCallback($pParams, $WsChannel) #forceref $pParams, $WsChannel ConsoleWrite(5 & @CRLF) EndFunc 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 November 5, 2021 by NewCommer Link to comment Share on other sites More sharing options...
JockoDundee Posted November 5, 2021 Share Posted November 5, 2021 4 hours ago, NewCommer said: Because I ran script and it only printed to console number 1 Your program is going to exit right after your DllCall(). You’re lucky to have gotten even the first Callback before it terminated. Add a sleep loop after the call: While Sleep(10) WEnd Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Danyfirex Posted November 6, 2021 Share Posted November 6, 2021 Hi, Where can I see library's Documentation? is a free library? Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now