Jump to content

Need help with dllcall callback


Recommended Posts

Hello,
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);   
    fflush(stdout);
}


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");
        FreeLibrary(hinstLib);
        return 1;
    }

    if (InitPAnsiChar(*MyCallBackPAnsiChar))
    {
        printf("\nInit DLL with InitPAnsiChar successfull");
        }
        else
        {
        // Unload DLL file
        FreeLibrary(hinstLib);
        return 0;
    }


    while(1)
    {
        
    }
    //return 0;
}

 

Link to comment
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
    Sleep(30)
WEnd


; Delete callback function.
DllCallbackFree($hCallback)
;close dll
DllClose($hDll)
Exit

; 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()
    $IsRunning=False
EndFunc

Saludos

Edited by Danyfirex
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

×
×
  • Create New...