Jump to content
bladem2003

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;
}

 

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
    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

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 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
      https://docs.microsoft.com/en-us/windows/desktop/dlls/about-dynamic-link-libraries
      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?
      Skysnake
    • By supersonic
      Hi -
      Currently I'm playing around with Windows Credential Manager. I'm trying to access it with DllCall("advapi32.dll", ...) using the functions 'CredWriteW', 'CredReadW' and 'CredDeleteW'. All well. Another function I have to deal with is 'CredEnumerateW': https://docs.microsoft.com/en-us/windows/desktop/api/wincred/nf-wincred-credenumeratew/ .
      That's the test code I have so far:
      #include <Array.au3> #include <String.au3> Local $tCredentialsCount = DllStructCreate("DWORD;") Local $tPointerToArrayOfPointers = DllStructCreate("PTR;") ; Local $tPointerToArrayOfPointers = DllStructCreate(_StringRepeat("PTR;", 200)) ; ??? Local $aResult = DllCall("advapi32.dll", "BOOL", "CredEnumerateW", _ "WSTR", Null, "DWORD", 1, "DWORD", DllStructGetPtr($tCredentialsCount), "PTR", DllStructGetPtr($tPointerToArrayOfPointers)) If (Not @error) Then Local $iCredentialsCount = DllStructGetData($tCredentialsCount, 1) _ArrayDisplay($aResult, $iCredentialsCount) Local $hPointerToArrayOfPointers = DllStructGetData($tPointerToArrayOfPointers, 1) MsgBox(0, "$hPointerToArrayOfPointers", $hPointerToArrayOfPointers) ; Fails... For $i = 1 To 10 ; $iCredentialsCount MsgBox(0, $i & "___" & (($i * 2) - 1), DllStructGetData($tPointerToArrayOfPointers, ($i * 2) - 1)) Next $tCredentialsCount = 0 $tPointerToArrayOfPointers = 0 DllCall("advapi32.dll", "NONE", "CredFreeW", "PTR", $hPointerToArrayOfPointers) EndIf The DllCall seems to function properly - I get a valid count of credentials (on my computer ~ 133) and a pointer "to array of pointers".
      What is meant by "array of pointers"?
      Microsoft says: Pointer to an array of pointers to credentials. The returned credential is a single allocated block. Any pointers contained within the buffer are pointers to locations within this single allocated block.
      How to access these pointers... Contained within the buffer???
      Any information you can provide me would be greatly appreciated.
    • By Stacker
      Hi all,
      i want to start a new application that capture a screen or image from webcam an read all barcode inside the picture.
      I have test this code https://www.autoitscript.com/forum/topic/27925-webcam-example/
      Works fine for my webcam.
      Now i need to read all barcodes (code 128 code39, no 2d) inside the picture. I have found this https://www.codeproject.com/Articles/42852/Reading-Barcodes-from-an-Image-III
      It's possible to make a dll from VB source i linked  with this  parameters :  filename, Array of barcode founded, error code and launch from Autoit with function ?
      Anyone can help me to make dll and autoit function, i don't know VB.
      Thanks
    • By Terenz
      Hello,
      Someone is so kind to compile for me this DLL?
      https://github.com/stephane/libmodbus/tree/master/src/win32
      Many thanks!
×
×
  • Create New...