Jump to content

Need help with dllcall callback

Recommended Posts

i need help to translate the c code to autoit .
I don't understand the callback function.


#include <windows.h>
#include <stdio.h>

// native IR Data by PAnsiChar
typedef void CALLBACK CallBackPAnsiChar(char*, char*, char*, char*);
typedef int (__stdcall *impInitPAnsiChar)(CallBackPAnsiChar);

CALLBACK MyCallBackPAnsiChar(char* Protocol, char* Address, char* Command, char* Flags)
    printf("\nIR Data received: Protocol: %s, Address: 0x%s, Command: 0x%s, Flags: 0x%s", Protocol, Address, Command, Flags);   

int main(int argc, char **argv)
    impInitPAnsiChar InitPAnsiChar = NULL;
    // Load DLL file
    HINSTANCE hinstLib = LoadLibrary(TEXT("USB_IR_Remote_Receiver.dll"));
    if (hinstLib == NULL) {
        printf("\nERROR: unable to load DLL\n");
        return 1;

    // Get function pointer InitPAnsiChar
    InitPAnsiChar = (impInitPAnsiChar)GetProcAddress(hinstLib, "InitPAnsiChar");
    if (InitPAnsiChar == NULL) {
        printf("\nERROR: unable to find DLL function\n");
        return 1;

    if (InitPAnsiChar(*MyCallBackPAnsiChar))
        printf("\nInit DLL with InitPAnsiChar successfull");
        // Unload DLL file
        return 0;

    //return 0;


Share this post

Link to post
Share on other sites

Hello. I think it should look like:

HotKeySet("{ESC}", "_Terminate")

Local $IsRunning=True

Local $hDll=DllOpen("USB_IR_Remote_Receiver.dll")

; Create callback function.
Local $hCallback = DllCallbackRegister("_MyCallBackPAnsiChar", "none", "str;str;str;str")

; Call InitPAnsiChar
DllCall($hDll, "int", "InitPAnsiChar", "ptr", DllCallbackGetPtr($hCallback))

While $IsRunning

; Delete callback function.
;close dll

; Callback Procedure
Func _MyCallBackPAnsiChar($sProtocol,$sAddress,$sCommand,$sFlags)
    ConsoleWrite(StringFormat("IR Data received: Protocol: %s, Address: 0x%s, Command: 0x%s, Flags: 0x%s", $sProtocol, $sAddress, $sCommand, $sFlags) & @CRLF)
EndFunc   ;==>_EnumWindowsProc

Func _Terminate()


Edited by Danyfirex

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

  • Similar Content

    • By xYuri
      This simple dllcall gives me error 5, access denied,
      Func _WinAPI_VkKeyScan($__key) _WinAPI_SetLastError(0) $res = DllCall('User32.dll', 'SHORT', 'VkKeyScan', 'CHAR', $__key) _xConsole('res: '&$res) $_LastErr = _WinAPI_GetLastError() If $_LastErr <> 0 Then _xConsole('Err: {' & $_LastErr & '}> ' & _WinAPI_GetLastErrorMessage()) Return $res EndFunc Am i doing something wrong?
      Also tried VkKeyScanA and W
      I want to send `:` via PostMessage() WM_KEYDOWN
    • By RAMzor
      Hello all!
      I got the Acroname Programmable USB Hub based on BrainStem platform. I will use it to manage ports and read current.
      They have development kit (BRAINSTEM DEVELOPMENT KIT) with examples for any languages like C#, C++, LabVIEW and python but no AutoIt.
      The kit include BrainStem2.dll (x32 and x64), BrainStem2_LabVIEW.dll, BrainStem2CLI.dll and many examples.
      Anyone used this dll and implemented it in AutoIt?
      Please share some example for Device Discovering, User LED Flashing or power enable/disable on port to start play with this HUB
      BrainStem Reference 
      BrainStem2 lib+example.7z USB HUB User Manual s79-usbhub-3p_v1.10_0.pdf
    • By matwachich
      Hi guys!
      A pretty simple UDF to convert HTML to PDF using wkHTMLtoPDF.
      It uses the C API of the tool (DLL), so no external process, no ActiveX or COM sh*t.
      See the example, and the documentation of wkHTMLtoPDF.
    • By Skysnake
      This is relevant
      From here https://stackoverflow.com/questions/3454315/is-it-possible-to-pin-a-dll-in-memory-to-prevent-unloading
      I use several UDFs on the Forum to do various things.  Those UDFs work very well.
      Effectively the UDFs are DLL wrappers, that make it possible to access DLL functions easily without the long hard slog of DLLCall() every time.
      However, I have now run into the issue that multiple UDF DLLCalls are slow. Not mind numbingly slow, but slow enough to become noticeable with a large of repeated function calls.
      So I was wondering, is it possible to "load a DLL into memory" and leave it there for the duration of my script's lifetime, avoid repeated DLL on-disk reads with a persistent in memory DLL?
      From Microsoft
      Looks like what I want to do is: load-time dynamic linking,
      So next question, (a) how do I do this with AutoIt (b) How would this impact on standard AutoIt type DLL calls?
      The point is speed.  Is there a different approach?
      Or am I barking up the wrong tree?
  • Create New...