Jump to content

Search the Community

Showing results for tags 'dllcall'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

  1. hi, I made a software for managing dtmf tones. For the moment the pc audio output is connected to an Arduino with an mt8870 module which decodes the tone and returns the correct value via serial. I wanted to make sure not to use external hardware and so I tried with the bass.dll library to read the microphone input. I can read the volume and interpret the data, but I haven't found a way to handle the dtmfs. Searching the internet I found a project with source in Delphi and C++ with examples to import a library called DTMFScanner.dll (https://www.3delite.hu/Object Pascal Developer Resources/download.html#dtmf) the DTMFScannerLibrary.h file is attached to this post. There are examples on how to use the external library with Delphi too I tried to modify an example of the bass library to integrate the request for the DTMFScanner.dll library but it always returns the value 0. I'm afraid I'm using the wrong library recall method This is my script: #include 'Bass.au3' #include <WinAPICOM.au3> #include <WinAPIConv.au3> #include <Array.au3> Global $hStream, $iLong, $nLeft, $nRight, $iColor Global $ID_GUI = GUICreate('BASS Audio Levels', 190, 200, -1, -1, Default, 0x00000008) GUICtrlCreateLabel('L', 52, 20, 34, 22) GUICtrlCreateLabel('R', 82, 20, 34, 22) Global $ProgressBarL = GUICtrlCreateProgress(50, 40, 14, 100, 0x04) Global $ProgressBarR = GUICtrlCreateProgress(80, 40, 14, 100, 0x04) Global $InputL = GUICtrlCreateLabel('', 50, 150, 34, 22) Global $InputR = GUICtrlCreateLabel('', 80, 150, 34, 22) Global $DtmlDLL Global $parameters = DllStructCreate("ptr FileName; dword Channel; float Treshold; int Thread; int64 User; ptr DetectCallback") Global $inputChannel = 3 ;<------- my mic input Global $result1 GUISetOnEvent(-3, '_Exit') Opt('GUIOnEventMode', 1) GUISetState(@SW_SHOW, $ID_GUI) _BASS_Startup(@ScriptDir & '\Bass.dll') If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC1') _BASS_Init(16, -1, 44100, 0, 'NULL') If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC2') _BASS_RecordInit(-1) If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC3') ; choose input. I use n.3 in this moment _BASS_RecordSetInput($inputChannel, $BASS_INPUT_TYPE_WAVE, 1) ;~ Global $hStream = _BASS_RecordStart(44100, 2, 0, 0) Global $hStream = _BASS_RecordStart(44100, 2, $BASS_SAMPLE_FLOAT);_WinAPI_MakeLong(0, 10)) If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC4') _BASS_ChannelPlay($hStream, True) If @error Then Exit MsgBox(16, 'BASS Function Error', 'EC5') While _BASS_ChannelIsActive($hStream) ;********************************* VUMETER WITH BASS.DLL ******************************************************* $iLong = _BASS_ChannelGetLevel($hStream) $nLeft = _BASS_LoWord($iLong) / 32768 * 100 $nRight = _BASS_HiWord($iLong) / 32768 * 100 $nLeft = Round($nLeft) $nRight = Round($nRight) ; $iColor = 0xFFFFFF If $nLeft > 99 Then $iColor = 0xFF0000 GUICtrlSetColor($ProgressBarL, $iColor) $iColor = 0xFFFFFF If $nRight > 99 Then $iColor = 0xFF0000 GUICtrlSetColor($ProgressBarR, $iColor) ; GUICtrlSetData($ProgressBarL, $nLeft) GUICtrlSetData($ProgressBarR, $nRight) GUICtrlSetData($InputL, $nLeft); <-- Left numeric audio level GUICtrlSetData($InputR, $nRight); <-- Right numeric audio level ; Sleep(10) ;********************************* LOAD EXTERNAL DTMFScanner.dll ******************************************************* $DtmlDLL = DllOpen("DTMFScanner.dll") if @error then ConsoleWrite("DTMFScanner.dll Load Error!!" & @CRLF) Else ConsoleWrite("DTMFScanner external Funcion ok" & @CRLF) $parameters = DllStructCreate("ptr FileName; dword Channel; float Treshold; int Thread; int64 User; ptr DetectCallback") DllStructSetData($parameters, "FileName", DllStructCreate("wchar[260]")) DllStructSetData($parameters, "Channel", $inputChannel) DllStructSetData($parameters, "Treshold", 0.5) DllStructSetData($parameters, "Thread", 0) DllStructSetData($parameters, "User", 0) DllStructSetData($parameters, "DetectCallback", "DetectCallback") $result = DllCall($DtmlDLL, "int", "DTMFScan", "ptr", DllStructGetPtr($parameters)) if @error then ConsoleWrite("error = " & @error & @CRLF) DllClose($DtmlDLL) ConsoleWrite("DTMF = " & $result[0] & " - other returned values (I don't know which ones): " & ($result[1]) & @CRLF) EndIf Sleep(40) WEnd Func _Exit() _BASS_RecordFree() _BASS_Free() GUIDelete($ID_GUI) Exit EndFunc DTMFScannerLibrary.h: //******************************************************************************************************************************** //* * //* DTMF Scanner Library 1.0.4.25 © 3delite 2023 * //* See DTMF Scanner Library ReadMe.txt for details. * //* * //* Licenses available for usege of this library: * //* Freeeware License: €15 * //* http://www.shareit.com/product.html?productid=301011183 * //* Shareware License: €25 * //* http://www.shareit.com/product.html?productid=301011182 * //* Commercial License: €125 * //* http://www.shareit.com/product.html?productid=301011181 * //* * //* https://www.3delite.hu/Object%20Pascal%20Developer%20Resources/DTMFScannerLibrary.html * //* * //* If you have any questions or enquiries please mail: 3delite@3delite.hu * //* * //* Good coding! :) * //* 3delite * //******************************************************************************************************************************** #pragma once #ifdef _WIN32 // Windows //* .dll file name #define FILENAME_DLL_DTMF_SCANNER_LIBRARY "DTMFScanner.dll" #define DTMFSLIBCALL __stdcall //* Exported function names (Windows) #define NAME_DTMFScan "DTMFScan" #endif //* Error codes #define DTMFSL_OK = 0 #define DTMFSL_ERROR = 1 #ifdef _WIN32 #include <wtypes.h> typedef unsigned __int64 QWORD; #else #include <stdint.h> #define WINAPI #define CALLBACK typedef uint8_t BYTE; typedef uint16_t WORD; typedef uint32_t DWORD; typedef uint64_t QWORD; typedef void* HANDLE; #ifndef __OBJC__ typedef int BOOL; #endif #ifndef TRUE #define TRUE 1 #define FALSE 0 #endif #endif typedef enum { dtetStart = 0, dtetContinuing = 1, dtetEnd = 2 } TDTElementType; //* Callback typedef int(DTMFSLIBCALL *TDetectCallback)(int DTMF, TDTElementType Status, float Position, QWORD User); typedef struct { LPWSTR FileName; DWORD Channel; float Treshold; BOOL Thread; QWORD User; TDetectCallback DetectCallback; } *PDTMFScannerParameters, TDTMFScannerParameters; //* Exported functions typedef int(DTMFSLIBCALL* t_DTMFScan)(TDTMFScannerParameters* Parameters); #ifdef __cplusplus extern "C" { #endif static HMODULE DTMFScannerLibraryDLLHandle = NULL; BOOL DTMFScannerLibraryDLLLoaded = FALSE; t_DTMFScan DTMFScan = NULL; #ifdef __cplusplus } #endif BOOL InitDTMFScannerLibrary() { DTMFScannerLibraryDLLHandle = LoadLibrary(FILENAME_DLL_DTMF_SCANNER_LIBRARY); if (NULL != DTMFScannerLibraryDLLHandle) { DTMFScan = (t_DTMFScan)GetProcAddress(DTMFScannerLibraryDLLHandle, NAME_DTMFScan); if (NULL == DTMFScan) { DTMFScannerLibraryDLLLoaded = FALSE; } else { DTMFScannerLibraryDLLLoaded = TRUE; } } return DTMFScannerLibraryDLLLoaded; } BOOL FreeDTMFScannerLibrary() { if (NULL != DTMFScannerLibraryDLLHandle) { DTMFScannerLibraryDLLLoaded = !FreeLibrary(DTMFScannerLibraryDLLHandle); } return !DTMFScannerLibraryDLLLoaded; } DTMFScannerLibrary.pas: //******************************************************************************************************************************** //* * //* DTMF Scanner Library 1.0.4.25 © 3delite 2023 * //* See DTMF Scanner Library ReadMe.txt for details. * //* * //* Licenses available for usege of this library: * //* Freeeware License: €15 * //* http://www.shareit.com/product.html?productid=301011183 * //* Shareware License: €25 * //* http://www.shareit.com/product.html?productid=301011182 * //* Commercial License: €125 * //* http://www.shareit.com/product.html?productid=301011181 * //* * //* https://www.3delite.hu/Object%20Pascal%20Developer%20Resources/DTMFScannerLibrary.html * //* * //* If you have any questions or enquiries please mail: 3delite@3delite.hu * //* * //* Good coding! :) * //* 3delite * //******************************************************************************************************************************** unit DTMFScannerLibrary; interface type TDTElementType = (dtetStart, dtetContinuing, dtetEnd); type TDetectCallback = function(DTMF: Integer; Status: TDTElementType; Position: Single; User: UInt64): Integer; stdcall; type PDTMFScannerParameters = ^TDTMFScannerParameters; TDTMFScannerParameters = record FileName: PChar; Channel: Cardinal; Treshold: Single; Thread: LongBool; User: Int64; DetectCallback: TDetectCallback; end; function DTMFScan(var Parameters: TDTMFScannerParameters): Integer; stdcall; external 'DTMFScanner.dll'; implementation end. Delphi Example: unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, bass, Vcl.StdCtrls, DTMFScannerLibrary; type TForm1 = class(TForm) Memo1: TMemo; Button2: TButton; Label2: TLabel; Edit2: TEdit; ComboBoxInput: TComboBox; Label1: TLabel; Button1: TButton; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } protected procedure WndProc(var Message: TMessage); override; public { Public declarations } procedure ListDevices; end; Const MSG_DTMF_DETECTED = WM_USER * 4 + 111; var Form1: TForm1; Counter: Integer; implementation {$R *.dfm} procedure TForm1.ListDevices; var Device: AnsiString; Count: Integer; Info: BASS_DEVICEINFO; begin ComboBoxInput.Items.Clear; Count := 0; while BASS_RecordGetDeviceInfo(count, Info) do begin Device := Info.name; ComboBoxInput.Items.Add(String(Device)); Inc(Count); end; ComboBoxInput.ItemIndex := - 1; ComboBoxInput.Text := 'Select...'; end; procedure TForm1.FormCreate(Sender: TObject); begin BASS_Init(- 1, 44100, 0, Handle, nil); ListDevices; end; procedure TForm1.FormDestroy(Sender: TObject); begin BASS_Free; end; procedure TForm1.WndProc(var Message: TMessage); begin case Message.Msg of MSG_DTMF_DETECTED: begin Form1.Memo1.Lines.Append('Tone detected: ' + Char(Message.WParam)); end; else inherited WndProc(Message); end; end; function DetectCallback(DTMF: Integer; Status: TDTElementType; Position: Single; User: UInt64): Integer; stdcall; begin //* List only new detections if Status = dtetStart then begin //* This callback is called from a thread, no UI access is allowed in threads so send the params to the main thread PostMessage(Form1.Handle, MSG_DTMF_DETECTED, wParam(DTMF), 0); Inc(Counter); end; Result := 0; end; procedure TForm1.Button1Click(Sender: TObject); begin //* Freeing the channel handle automatically terminates the scanning thread BASS_RecordFree; end; procedure TForm1.Button2Click(Sender: TObject); var Parameters: TDTMFScannerParameters; ChannelInput: HRecord; begin //StopProcessing := False; BASS_RecordFree; BASS_RecordInit(ComboBoxInput.ItemIndex); //* Always use BASS_SAMPLE_FLOAT flag ChannelInput := BASS_RecordStart(11025, 1, BASS_SAMPLE_FLOAT, nil, nil); Counter := 0; Parameters.FileName := nil; Parameters.Channel := ChannelInput; Parameters.Treshold := StrToFloat(Edit2.Text); Parameters.Thread := True; Parameters.User := 0; Parameters.DetectCallback := DetectCallback; DTMFScan(Parameters); end; end. the return in debug is always 0 and another values that change: DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02642090 DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02642748 DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02643A58 DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02642860 DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02642748 DTMFScanner external Funcion ok DTMF = 0 - other returned values (I don't know which ones): 0x02643BE8 Any idea to implement the DTMFScanner.dll? Thankyou very much! Marco DTMF_dialing.ogg bass.dll DTMFScanner.dll Bass.au3 DTMFScannerLibrary.h Unit1.pas DTMFScannerLibrary.pas
  2. Hi here's another UDF for the serial port. It is very similar to CommAPI using kernel32.dll, but all code is packed into a single file without any dependencies, not even using WinAPI.au3. It differs from existing UDF that it doesn't allow a timeout when reading, instead it always returns immediately, either with the requested amount ob bytes read or with a failure status. And of course there is a function provided to query the amount of available bytes in the receive buffer. The reason behind this design decision: You can do 1000 other things in the main loop while checking from time to time if enough data bytes arrived. There's no point to block the program waiting for the serial port. It is currently a work-in-progress, as I didn't test all functions yet. The code was developed and tested on Windows 7 64 bit. The ComUDF-Tests.au3 shows some tests and basic usage of the UDF. Maybe there's no reason to use this UDF, given the existence of the others UDFs, but I did it to get to know DllCall better - I use structs no only to pass but also to get data back (I don't use the array returned by DllCall to read that data, unless required). You're welcome to test it on older and newer Windows versions. Here's a list of the implemented functions: ; _ComListPorts ; _ComOpenPort ; _ComSetTimeouts ; _ComClosePort ; ; _ComSetBreak ; _ComClearBreak ; _ComGetInputcount ; _ComGetOutputcount ; _ComClearOutputBuffer ; _ComClearInputBuffer ; ; _ComSendByte ; _ComReadByte ; _ComSendBinary ; _ComReadBinary ; ; _ComSendChar ; _ComReadChar ; _ComSendCharArray ; _ComReadCharArray ; _ComSendString ; _ComReadString ; ; __ComClearCommError ; __PurgeComm Maze ComUDF.au3 ComUDF-Tests.au3
  3. We have here a working script (Found on this forum - someone said its best way to set timers) I want to set timers in my program cause AdLibRegister crashes, infinite loops etc. Its a working small program to test these timers below. #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> Global $iMemo _Main() Func _Main() Global $hGUI Global $timerID1 = 1, $timerID2 = 2 Global $callBackFunc1, $callBackFunc2 Global $timerName1, $timerName2 $hGUI = GUICreate("My Timers", 400, 296) $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() setTimer($callBackFunc1, $timerName1, $timerID1, 1000, 'hello') setTimer($callBackFunc2, $timerName2, $timerID2, 2000, 'hello2') While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd killTimer($timerName1, $callBackFunc1) killTimer($timerName2, $callBackFunc2) EndFunc ;==>_Main ; ================= MY FUNCS ============================ Func setTimer(ByRef $callBackFunc, ByRef $timerName, $timerID = 1, $time = 1000, $funcName = 'hello') $callBackFunc = DllCallbackRegister($funcName, "none", "hwnd;int;int;dword") $timerName = _WinAPI_SetTimer($hGUI, $timerID, $time, DllCallbackGetPtr($callBackFunc)) EndFunc Func killTimer($timerName, $callBackFunc) _WinAPI_KillTimer($hGUI, $timerName) DllCallbackFree($callBackFunc) EndFunc ; ============================================= ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Func _WinAPI_KillTimer($hWnd, $iIDEvent) Local $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $iIDEvent) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] <> 0 EndFunc ;==>_WinAPI_KillTimer Func _WinAPI_SetTimer($hWnd, $iIDEvent, $iElapse, $pTimerFunc = 0) Local $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iIDEvent, "int", $iElapse, "ptr", $pTimerFunc) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] EndFunc ;==>_WinAPI_SetTimer Func _TimerCallBackFunc($hWnd, $Msg, $iIDTimer, $dwTime) MemoWrite("Timer " & $iIDTimer & " Fired") For $i = 999 To 1 Step -1 ConsoleWrite($i & @CRLF) Next EndFunc ;==>_TimerCallBackFunc ; ============== Funs to call =============================== Func hello($hWnd, $nMsg, $iIDTimer, $dwTime) MemoWrite("Timer " & $iIDTimer & " Fired") For $i = 999 To 1 Step -1 ConsoleWrite($i & @CRLF) Next EndFunc ;==>_TimerCallBackFunc Func hello2($hWnd, $nMsg, $iIDTimer, $dwTime) MemoWrite("Timer " & $iIDTimer & " Fired") For $i = 999 To 1 Step -1 ConsoleWrite($i & @CRLF) Next EndFunc ;==>_TimerCallBackFunc And i wanted to apply these timers to my final program. I get error: error: doingThings() called by a previous line with 0 arg(s). Min = 4. First previous line calling this Func is 31. Func doingThings($hWnd, $nMsg, $iIDTimer, $dwTime) There are pieces of code below: There I replaced AdlibRegister by setTimer and calling it like in previous working program (just doingThings in last param in setTimer function) Func r_offOn_doingThings() If _Metro_CheckboxIsChecked($r_offOn_doingThings) Then _Metro_CheckboxUnCheck($r_offOn_doingThings) ;AdlibUnRegister("doingThings") killTimer($timerName1, $callBackFunc1) Else If _checkDeclared(True,False) == False Then ; check if is declared to run func (HP,TITLE,REGION)- core_funcs Else _Metro_CheckboxCheck($r_offOn_doingThings) setTimer($callBackFunc1, $timerName1, 1, 1600, "doingThings") ;AdlibRegister("doingsThings", 1800) EndIf EndIf EndFunc And function name with params looks like this Func doingThings($hWnd, $nMsg, $iIDTimer, $dwTime) EndFunc #include Timers.au3 #CS THere are globals vars: globalVariables/timers ByRef $callBackFunc: var ByRef $timerName: var $timerID = 1: var ID $time = 1000: how often call func $funcName: function to call #CE Global $timerID1 = 1, $timerID2 = 2 Global $callBackFunc1, $callBackFunc2 Global $timerName1, $timerName2 Func setTimer(ByRef $callBackFunc, ByRef $timerName, $timerID = 1, $time = 1000, $funcName = "doingThings") $callBackFunc = DllCallbackRegister($funcName, "none", "hwnd;int;int;dword") $timerName = _WinAPI_SetTimer($GUI, $timerID, $time, DllCallbackGetPtr($callBackFunc)) EndFunc Func killTimer($timerName, $callBackFunc) _WinAPI_KillTimer($GUI, $timerName) DllCallbackFree($callBackFunc) EndFunc Func _WinAPI_KillTimer($hWnd, $iIDEvent) Local $iResult = DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "int", $iIDEvent) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] <> 0 EndFunc ;==>_WinAPI_KillTimer Func _WinAPI_SetTimer($hWnd, $iIDEvent, $iElapse, $pTimerFunc = 0) Local $iResult = DllCall("user32.dll", "int", "SetTimer", "hwnd", $hWnd, "int", $iIDEvent, "int", $iElapse, "ptr", $pTimerFunc) If @error Then Return SetError(-1, -1, 0) Return $iResult[0] EndFunc ;==>_WinAPI_SetTimer Thats it. And why in first working program it does not say this function below is calling with 0 args but Min is 4? setTimer($callBackFunc1, $timerName1, 1, 1600, "doingThings") When I applied this code to my final program it wants 4 arguments in function call. I rode i cant pass parameters to the callback func . What I have to do. I tried something like this: Func doingThings($hWnd = Default, $nMsg = Default, $iIDTimer = Default, $dwTime = Default) but then function is not working dont know whats going on
  4. I've been working with the Windows Credentials store to store credentials for lots of RDP connections. I'm also using this code in other scripts to store and retrieve "legacy" credentials for my scripts that have a Save Password checkbox. All goes well, until someone requests a button to display a list of all saved credentials. I found the CredEnumerate call and it looks like it's working but the Target and UserName field that I want is stored inside an array of pointers and I can't figure out how to get data from inside that. I found a post from 2009 that talks about this, but there was never a solution. Below are my functions put into an example script. the _Credentials_Enumerate() is where i'm having problems. Anybody have some ideas? Thanks, Mike ;Credentials Manager #include <array.au3> #include <WinAPI.au3> ;Needed for the _WinAPI_GetLastError() ;------------------------------------------------------------------------ ;----- Add items into the Credentials Store ---------------------------- ;------------------------------------------------------------------------ ;~ _Cred_Add("MyCredStored", "ItsMe", "Secret1", "", 1) ;Add a Local Credentials so we can test the retrieval of a password ;~ $aAddCred = _Cred_Add("MyServer", "Domain\adminAccount", "MyS3cr3+P@ssw0rd") ;Add domain Credentials that can only be used with RDP and other such items ;~ _ArrayDisplay($aAddCred, "AddCred") ;------------------------------------------------------------------------ ;------------------------------------------------------------------------ ;----- Retrieve Credentials from the Credentials Store ----------------- ;------------------------------------------------------------------------ ;~ $aCreds = _Cred_Get("MyServer", 2) ;Retrieve Domain Cred's, won't have password in it ;~ _ArrayDisplay($aCreds, "Credentials") $aCreds = _Credentials_Enumerate() ;Get a list of all credentials currently stored on the system **(DOES NOT WORK)** ;------------------------------------------------------------------------ ;------------------------------------------------------------------------ ;----- Delete a Credential from the Credentials Store ------------------ ;------------------------------------------------------------------------ ;~ _Cred_Delete("MyServer") ;Delete the specified item from the Credential Store ;~ For $d = 1 to UBound($aCreds) - 1 ;~ _Cred_Delete($aCreds[$d][0]) ;Loop to delete all items found. **(DOES NOT WORK)** ;~ Next ;------------------------------------------------------------------------ ;================================================================================================ ;===== Add a Credential into the Credentials Store ============================================= ;================================================================================================ Func _Cred_Add($sTarget, $sUser, $sPassword, $sComm = "", $iType = 2) ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ; Create a structure to hold the Target object name DllStructSetData($structTarget, 1, $sTarget) ; Insert the target name into that Structure Local $structUser = DllStructCreate("wchar[100]") ; Create a structure to hold the UserName to use DllStructSetData($structUser, 1, $sUser) ; Insert the user name into the structure Local $structPwd = DllStructCreate("wchar[100]") ; Create a structure to hole the password to use DllStructSetData($structPwd, 1, $sPassword) ; Insert the password into the structure Local $structComment = DllStructCreate("wchar[100]") ; I don't see where this is used, but was in all the examples DllStructSetData($structComment, 1, $sComm) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error); Exit EndIf DllStructSetData($NewCred,"Flags",0) DllStructSetData($NewCred,"Type",$iType) ;2 = Domain, 1 = Generic DllStructSetData($NewCred,"TargetName",DllStructGetPtr($structTarget)) DllStructSetData($NewCred,"Persist",3) DllStructSetData($NewCred,"AttributeCount",0) DllStructSetData($NewCred,"UserName",DllStructGetPtr($structUser)) DllStructSetData($NewCred,"CredentialBlob",DllStructGetPtr($structPwd)) DllStructSetData($NewCred,"CredintialBlobSize",StringLen($sPassword)*2) DllStructSetData($NewCred,"Comment",DllStructGetPtr($structComment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif $Ret = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) $NewCred = 0 If IsArray($Ret) Then Return $Ret Else Return SetError(1) EndIf EndFunc ;_Cred_Add ;================================================================================================ ;===== Retrieve the Credentials for the specified item ========================================= ;================================================================================================ Func _Cred_Get($sTarget, $iType = 1) ;Type: 2=Domain, 1=Local. CAN'T RETURN DOMAIN PASSWORDS!!! Local $FuncRet[3] Local $structTarget = DllStructCreate("wchar[100]") DllStructSetData($structTarget,1,$sTarget) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif Local $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0, 'ptr*', 0) if $ret[0]=0 then Return SetError(1,0,$FuncRet) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata=DllStructCreate($structCREDENTIAL, $Ret[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $User = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $Password = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize/2) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $Comm = DllStructGetData($Comment, 1) Dim $FuncRet[] = [$User, $Password, $Comm] Return $FuncRet EndFunc ;_Cred_Get ;================================================================================================ ;===== Delete a specified item from the Credentials Store ====================================== ;================================================================================================ Func _Cred_Delete($sTarget, $iType = 2) ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ;Create a structure to hold the object name we want to delete DllStructSetData($structTarget, 1, $sTarget) ;Insert the Object Name into the Structure Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif ;Now send all the info into the DLL to delete the item $Ret = DllCall($hAdvapi32, 'bool', 'CredDeleteW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0) ;$iType 2 = Domain, 1 = Local EndFunc ;_Cred_Delete ;================================================================================================ ;===== Return a 2D array with the Target, UserName, Password for every item ==================== ;===== in the Credentials Store ==================== ;================================================================================================ Func _Credentials_Enumerate() ;https://msdn.microsoft.com/en-us/library/windows/desktop/aa374794(v=vs.85).aspx ;https://www.autoitscript.com/forum/topic/99705-credenumerate-function-call/?do=findComment&comment=715159 Local $aResult Local $structCREDENTIAL = "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" $aResult = DllCall('advapi32.dll', 'int', 'CredEnumerateW', _ ;Call the Unicode version of CredEnumerate 'wstr', Null, _ ;Don't use any filter since I want everything returned 'uint', 1, _ ;1 = CRED_ENUMERATE_ALL_CREDENTIALS 'uint*', '', _ ;Return the Count of all stored credentials 'ptr*', '') ;Returns a pointer to an Array of pointers? If @error Or ($aResult[0] = 0) Then ConsoleWrite('Error: ' & @error & @TAB & 'Extended: ' & @extended & @CRLF) ConsoleWrite(_WinAPI_GetLastError() & @CRLF) ;1168 = Nothing matches the filter, 1312 = no credential set for this user, 1004 = Flag/Filter options are wrong Return SetError(1) EndIf ConsoleWrite("DllCall Returned = " & $aResult[0] & @CRLF & "Credential Count = " & $aResult[3] & @CRLF & "Pointer to Creds Array = " & $aResult[4] & @CRLF) For $c = 2 to $aResult[3] ;Create enough struct for each item in each credential found $structCREDENTIAL &= "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Next Local $tdata = DllStructCreate($structCREDENTIAL, $aResult[4]) ;Insert all the data from the array of pointers into this struct Local $FullTarget = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'TargetName')) ;Create and Get the array storing TargetName Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) ;Create and Get the array storing Username Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') ;Get the password blob Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) ;Create and get the password text Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) ;Don't see a need for comments ;Retrieve the data For $c = 1 to $aResult[3] Local $Target = DllStructGetData($FullTarget, $c) ;Retrieve the Target Name from the item # Local $User = DllStructGetData($userName, $c) ;Retrieve the User Name from the item # Local $Password = StringLeft(DllStructGetData($credentialBlob, $c), $CredentialBlobSize/2) ;Retrieve the password, Only works for 1, legacy. domain creds will not return passwords Local $Comm = DllStructGetData($Comment, $c) ;Don't need comments but getting it since it's in all the examples ConsoleWrite("Loop = " & $c & ": Target = " & $Target & ": UserName = " & $User & ": Comment = " & $Comm & @CRLF) Next If $aResult[3] > 0 Then $aCreds = DllCall('advapi32.dll', 'none', 'CredFree', 'ptr', $aResult[4]) ;This is just used to release the pointer. Call when done EndIf EndFunc ;_Credentials_Enumerate
  5. Hello Autoit, I'm very new to DllCall function, in fact never used it, but I'm just curious about it. I found @toasterking's awesome beginner friendly dll GUI: I searched for some easier functions (less input / less output parameters), and I found GetFileSize function (I didn't modify his code, just using the GUI): https://learn.microsoft.com/en-gb/windows/win32/api/fileapi/nf-fileapi-getfilesize So, this is what I did: The function itself is executing like this, but the output is 0 and -1 DllCall("kernel32.dll","int","GetFileSize","HANDLE","D:\DllCall GetFileSize Example.au3","DWORD*","$hello") Then, I tried to execute my script (very simple) and put it into D drive: ;DllCall("kernel32.dll", "int", "GetFileSize", "HANDLE", "D:\DllCall GetFileSize Example.au3") $aDllCallReturn = DllCall("kernel32.dll","int","GetFileSize","HANDLE","D:\DllCall GetFileSize Example.au3","DWORD*","$hello") For $i = 0 To UBound($aDllCallReturn) - 1 ConsoleWrite($i & ": " & $aDllCallReturn[$i] & @CRLF) ;MsgBox(0, $i, $aDllCallReturn[$i]) Next ;ConsoleWrite($hello & @CRLF) The result is as the following (same as the screenshot): 0: -1 1: 0x00000000 2: 0 This file size is 403 bytes in my computer, it's very small, I expected to see 403 somewhere, but I don't know where I made it wrong. So, now I have some questions: 1. Do I really need to use lpFileSizeHigh or can I use "hello"? 2. Do I always have to put $ in the beginning of the parameter? I tried without $ in his GUI, I got an error. So, I think $ is a must. 3. But if I write as $hello (expecting this will store the file size), when I ConsoleWrite it, Autoit becomes angry because "undeclared global variable". 4. If somehow $hello will be the output to my file size, why do I need to return an array $aDllCallReturn which contains 3 elements? So, I have one $hello + 3 items from the array = I have 4 outputs total. But Microsoft says this function has only one return "[out, optional] LPDWORD lpFileSizeHigh ". I'm confused. Please note that; the goal for me is to use the DllCall function, not to get the file size by using FileGetSize() or some other existing functions.
  6. Hi, My AutoIt script is as folllows: ;use for calling function add2NosA in dll ;Local $vNo1 = 33 ;Local $vNo2 = 11 ;use for calling function sortNos in dll Local $vNo1 = [11,7,9] Local $vNo2 = [1,3,2] ; _ArrayDisplay($vNo1, "vNo1 display") ; _ArrayDisplay($vNo2, "vNo2 display") ;Local $hWnd = DllOpen("E:\CV-Dell-1\autoit3\myComObj1.dll") Local $hWnd = ObjCreate("myComObj1.clsMath") if (@error) Then MsgBox (0, "Error", "Error1 = " & @error) Exit EndIf ;function call method - DllCall with function name ;Local $aRes = DllCall($hWnd, "int", "addNosA", "int", $vNo1, "int", $vNo2) ;Local $aRes = DllCall($hWnd, "Ptr", "sortNos", "Array", $vNo1, "Array", $vNo2) ;function call method - $hWnd.<function name> ;Local $aRes = $hWnd.add2NosA($vNo1, $vNo2) ; this works fine with ObjCreate Local $aRes = $hWnd.sortNos($vNo1, $vNo2) if (@error) Then MsgBox (0, "Error", "Error2 = " & @error) DllClose($hWnd) Exit EndIf ;use appropriate msgbox ;MsgBox(0,"Result", "Result = " & $vNo1[0]) MsgBox(0,"Result", "Result = " & $aRes) _ArrayDisplay($vNo1, "vNo1 display") _ArrayDisplay($aRes , "aRes display") DllClose($hWnd) My VB.Net - ClassLibrary - Dll - COM obj is as follows - has 2 functions - add2NosA and sortNos: <ComClass(clsMath.ClassId, clsMath.InterfaceId, clsMath.EventsId)> Public Class clsMath Public Const ClassId As String = "3A42F85E-24C8-4BAA-91B5-AE56C4683C13" Public Const InterfaceId As String = "D99D7C79-2BA7-4A33-B7BC-9B7F19FDF828" Public Const EventsId As String = "CA128AC4-580C-4112-9EAD-8D1599E3F37A" Public Sub New() MyBase.New() End Sub Public Function add2NosA(ByVal no1 As Integer, ByVal no2 As Integer) As Integer Return (no1 + no2) End Function Public Sub sortNos(ByRef no1 As Array, ByRef no2 As Array) Array.Sort(no1) no2 = no1 End Sub End Class Over all I tried various 8 options mentioned in the attached Excel file - with only 1 combination working. Overall could not make Array returned capture in AutoIt script. Can someone help please? Thanks in advance. Options-Tried-Matrix-Results.xlsx
  7. I have create a function in FreeBasic like below: Extern "Windows-MS" Type tA f1 As Integer f2 As Integer End Type Public Function _switchOrder(ByVal no1 As Integer, ByVal no2 As Integer) As tA Export Dim result As Integer Dim taa As tA taa.f1 = no2 taa.f2 = no1 Return taa End Function End Extern Caller AutoIt code is: #include <MsgBoxConstants.au3> Global Const $sTag_ftdi_version_info="struct; int no1a; int no2a; endstruct" Local $aRet=DllCall("Math1.dll","Ptr","_switchOrder", "Int", 10, "Int", 30) ;MsgBox (0,"",@error & "-" & $aRet[0] & "-" & $aRet[1]& "-" & $aRet[2]) Local $t_ftdi_version_info=DllStructCreate($sTag_ftdi_version_info,$aRet[0]) MsgBox (0,"msg1=",@error & "---" & $aRet[0] & "-" & $aRet[1]& "-" & $aRet[2]) ;Local $retData1 = DllStructGetData($t_ftdi_version_info,"",1) Local $retData1 = DllStructGetData($t_ftdi_version_info,"no1a") MsgBox (0,"msg2=",@error & "--" & $retData1) ;Local $retData1 = DllStructGetData($t_ftdi_version_info,"",2) Local $retData1 = DllStructGetData($t_ftdi_version_info,"no2a") MsgBox (0,"msg2=",@error & "--" & $retData1) ;ConsoleWrite(DllStructGetData($t_ftdi_version_info,"",2) & "--" & @error) ;ConsoleWrite(DllStructGetData($t_ftdi_version_info,"no2a") & @CRLF) ;ConsoleWrite(DllStructGetData($tversion_str,1) & @CRLF) Getting error 2 for DllStructGetData or it give Close Application AutoIt popup message. Certainly DllCall is not returning pointer to the Structure in $aRet[0] hence issue. Can someone help me fix this please? Thanks in advance.
  8. 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 Edit: I want to send `:` via PostMessage() WM_KEYDOWN
  9. 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
  10. 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.
  11. Hello, I'm trying to figure out how to add attributes to a Credentials Store. I have been using it to store Creds and I was using the Comments to store some limited data but I'd really like to start using the 64 possible Attributes so I don't need to use the Registry to store misc information my script needs. I have been trying to figure this our for a few days now and I'm able to create the structure, but it fails with Invalid Parameter when trying to add the item to the store. Any ideas or pointers to where to get some further information on this? Thanks, Mike #include <Crypt.au3> #include <Array.au3> #include <WinAPI.au3> $sEncryptionKey = @ScriptName & 'MyS3cur!tyK3y' & @UserName $sCredName = "AttributeTest" $sUserID = "MyUserID" $sPassword = "SecretP@ssw0rd" $sDatabase = "StoredCommentHere" $sAttribute1 = "ALM.NoReply" $sAttribute2 = "Defect #?BG_BUG_ID in ?PROJECT, Status = ?BG_STATUS, Severity = ?BG_SEVERITY" $sAttribute3 = "C:\Users\MyProfile\Documents\ALM_Reports" $sAttribute4 = "UserName1,QA_Analyst|UserName2,Business_Analyst|UserName3,QA_Analyst|UserName4,QA_Analyst|UserName5,Business_Analyst|UserName6,QA_Analyst" Global $aAttribute[4, 2] = [["eMailFrom", $sAttribute1], ["eMailSubject", $sAttribute2], ["reportFldr", $sAttribute3], ["DefaultUsers", $sAttribute4]] ;Add something to the Credential Store $aAdd = _Cred_Add_WithAttributes($sCredName, $sUserID, StringEncrypt(True, $sPassword, $sEncryptionKey), $sDatabase, 1, $aAttribute) If @error Then MsgBox(0, "Error", "Failed to add credentials to " & $sCredName) Exit EndIf Func _Cred_Add_WithAttributes($sTarget, $sUser, $sPassword, $sComm = "", $iType = 2, $aAttribute = "") ;Type: 2=Domain, 1=Local Local $structTarget = DllStructCreate("wchar[100]") ; Create a structure to hold the Target object name DllStructSetData($structTarget, 1, $sTarget) ; Insert the target name into that Structure Local $structUser = DllStructCreate("wchar[100]") ; Create a structure to hold the UserName to use DllStructSetData($structUser, 1, $sUser) ; Insert the user name into the structure Local $structPwd = DllStructCreate("wchar[100]") ; Create a structure to hold the password to use DllStructSetData($structPwd, 1, $sPassword) ; Insert the password into the structure Local $structComment = DllStructCreate("wchar[100]") ; Comments seem to only work where Type = 1 legacy DllStructSetData($structComment, 1, $sComm) ;-------------------------------------------------------------------------------------------------------------------- ;-- CREDENTIAL_ATTRIBUTE structure https://msdn.microsoft.com/en-us/library/windows/desktop/aa374790(v=vs.85).aspx ;-------------------------------------------------------------------------------------------------------------------- Local $aAttrirb[UBound($aAttribute)] Local $tagCREDENTIAL_ATTRIBUTE = "" & _ "wchar Keyword;" & _ "DWORD Flags;" & _ "DWORD ValueSize;" & _ "wchar Value" For $i = 0 to UBound($aAttribute) - 1 $aAttrirb[$i] = DllStructCreate($tagCREDENTIAL_ATTRIBUTE) If @error Then ConsoleWrite("Error on $aAttrib[" & $i & "] = " & @error & @CRLF) Exit EndIf DllStructSetData($aAttrirb[$i],"Keyword",StringRight($aAttribute[$i][0], 256)) ;Name for the Attribute to use, 256 characters max If @error Then ConsoleWrite("Error adding Keyword to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"Flags",0) ;Should always be 0 If @error Then ConsoleWrite("Error adding Flags to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"ValueSize",256) ;Max = 256 If @error Then ConsoleWrite("Error adding ValueSize to $aAttrib[" & $i & "] = " & @error & @CRLF) DllStructSetData($aAttrirb[$i],"Value",StringRight($aAttribute[$i][1], 256)) ;Take the right most 256 characters if they put in to many If @error Then ConsoleWrite("Error adding Value to $aAttrib[" & $i & "] = " & @error & @CRLF) Next ;-------------------------------------------------------------------------------------------------------------------- Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error); Exit EndIf DllStructSetData($NewCred,"Flags",0) DllStructSetData($NewCred,"Type",$iType) ;2 = Domain, 1 = Generic DllStructSetData($NewCred,"TargetName",DllStructGetPtr($structTarget)) DllStructSetData($NewCred,"Persist",3) ;save to roaming profile = 3 ;Problem with this section, as if I comment out, it adds but I need Attributes. DllStructSetData($NewCred,"AttributeCount",UBound($aAttrib)) ;max = 64 If @error Then ConsoleWrite("Error adding AttributeCount (1) = " & @error & @CRLF) For $i = 0 to UBound($aAttrirb) - 1 DllStructSetData($NewCred,"Attributes", DllStructGetPtr($aAttrirb[$i])) If @error Then ConsoleWrite("Error adding Attributes (" & $i + 1 & ") = " & @error & @CRLF) Next DllStructSetData($NewCred,"UserName",DllStructGetPtr($structUser)) DllStructSetData($NewCred,"CredentialBlob",DllStructGetPtr($structPwd)) DllStructSetData($NewCred,"CredintialBlobSize",StringLen($sPassword)*2) DllStructSetData($NewCred,"Comment",DllStructGetPtr($structComment)) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif $aRet = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) If @error Then ConsoleWrite("DllCall Error: " & @error & @CRLF) $NewCred = 0 ConsoleWrite("GetLastError = (" & _WinAPI_GetLastError() & ")" & @CRLF) ;87 = ERROR_INVALID_PARAMETER If IsArray($aRet) Then ConsoleWrite("Successfully performed the CredWriteW DLL call, Return = " & $aRet[0] & @CRLF) if UBound($aRet) > 1 Then _ArrayDisplay($aRet, "DllCall Returned") Return $aRet Else ConsoleWrite("Failed to perform the CredWriteW DLL call" & @CRLF) Return SetError(1) EndIf EndFunc Func _Cred_Get($sTarget, $iType = 2) ;Type: 2=Domain, 1=Local. CAN'T DECRYPT DOMAIN PASSWORDS!!! Local $FuncRet[3] Local $structTarget = DllStructCreate("wchar[100]") DllStructSetData($structTarget,1,$sTarget) Local $hAdvapi32 = DllOpen("Advapi32.dll") If $hAdvapi32 = -1 Then Msgbox(0, "Error", "Failed to connect to the Credentials Store") Exit Endif Local $Ret = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($structTarget), 'dword', $iType, 'dword', 0, 'ptr*', 0) if $ret[0]=0 then Return SetError(1,0,$FuncRet) Local $structCREDENTIAL= "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata=DllStructCreate($structCREDENTIAL, $Ret[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $User = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $Password = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize/2) ;Once the Add Attributes is working, I need to figure out how to retrieve the Attributes that I want, below is un-tested. ; Local $eMailFrom = DllStructCreate("wchar[256]", DllStructGetData($tdata, 'eMailFrom')) ; Local $eMail = DllStructGetData($eMailFrom, 4) ; Consolewrite("eMailFrom Attribute = (" & $eMail & ")" & @crlf ) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $Comm = DllStructGetData($Comment, 1) Dim $FuncRet[] = [$User, $Password, $Comm] If IsArray($FuncRet) Then Return $FuncRet Else Return SetError(1) EndIf EndFunc
  12. 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; }
  13. Hello All, I'm using "ImageSearch2015.au3" and i'm trying to figure out WHY, for the life of me, I can't find an image is hidden. So what I came up with, is as follows: _ImageSearchAreaHidden("C:\icon.png", 1, 0, 0, 800, 600, $x1, $y1, 80, 0) Func _ImageSearchAreaHidden($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance, $transparency = 0) Local $h, $result local $TestScreen = "C:\TestScreen.png" ;previsous screenshot of the image looking for, fully visible If Not FileExists($findImage) Then Return "Image File not found" If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0 If $h_ImageSearchDLL = -1 Then _ImageSearchStartup() If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage $result = DllCall($h_ImageSearchDLL, "str", "ImageSearchEx", "str", $TestScreen, "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage) If @error Then Return "DllCall Error=" & @error If $result = "0" Then Return False $array = StringSplit($result[0], "|") If (UBound($array) >= 4) Then $x = Int(Number($array[2])) ; Get the x,y location of the match $y = Int(Number($array[3])) If $resultPosition = 1 Then $x = $x + Int(Number($array[4]) / 2) ; Account for the size of the image to compute the centre of search $y = $y + Int(Number($array[5]) / 2) EndIf Return True EndIf EndFunc ;==>_ImageSearchAreaHidden Now when the folder with the icon is completely visible, it finds the icon without any issues, however if I cover up the icon, it no longer finds the image in the folder. Any ideas?
  14. So first things first the example in the help file for _WinApi_Enum_Windows has an error ;_ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, Default, "#|Handle|Class|Title|Text|Process") Should Be _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process") Next is a bit of helpful info on LPCSTR in a callback function it needs to be passed as a PTR DllCallbackRegister($sFUNCT, $sRETURN, "ptr") Finally on to my question I'd want to call EnumPropsEX and pass a string through lparam + append to it rather than declaring anything globally I can Come up with two ways to do this The second it a lot more code but possibly safer but the first way I think Should do 1. From a bit of testing It seems AutoIt won't overflow a DllStruct? 2. Are strings passed through DLL call guaranteed to be 'an ANSI string (a minimum of 65536 chars is allocated)' as the Helpfile clearly states? #include <Array.au3> #include <WinAPI.au3> Example() Func Example() Local $aWindows = _WinAPI_EnumWindows() Local $aResult[$aWindows[0][0]][6] For $i = 1 To $aWindows[0][0] $aResult[$i - 1][0] = "0x" & Hex($aWindows[$i][0], 8) $aResult[$i - 1][1] = $aWindows[$i][1] $aResult[$i - 1][2] = WinGetTitle($aWindows[$i][0]) $aResult[$i - 1][3] = WinGetText($aWindows[$i][0]) $aResult[$i - 1][4] = WinGetProcess($aWindows[$i][0]) $aResult[$i - 1][5] = _ArrayToString(EnumProps($aWindows[$i][0]), ", ", 1) Next _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process|Properties") EndFunc ;==>Example Func EnumProps($hWnd, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'str', "") If @error Or Not $aRet[0] Then $iErr = @error ConsoleWrite("EnumProps Error:" & $iErr & @CRLF) ElseIf $aRet[3] <> "" Then $aProps = StringSplit($aRet[3], ";") EndIf DllCallbackFree($hCb) Return SetError($iErr, 0, $aProps) EndFunc ;==>EnumProps Func _PropEnumProcEx($hWnd, $sProp, $hData, $pStr) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 ; + Null Char If $iSzStr > 1 Then Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) Local $tRetn = DllStructCreate('char[65535]', $pStr) DllStructSetData($tRetn, 1, DllStructGetData($tRetn, 1) & DllStructGetData($tProp, 1) & ";") EndIf Return 1 EndFunc ;==>_PropEnumProcEx ;-------------------------------------------------------------------------------------------------------------- Func EnumProps2($hWnd, $iSzBuffer = 4096, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $sProps Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') Local $tProps = DllStructCreate('int;int;char[' & $iSzBuffer & ']') DllStructSetData($tProps, 1, $iSzBuffer) ;BufferSz DllStructSetData($tProps, 2, $iSzBuffer) ;BufferRemaining ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'ptr', DllStructGetPtr($tProps)) If @error Or Not $aRet[0] Then $iErr = @error DllStructSetData($tProps, 2, 0) EndIf DllCallbackFree($hCb) $sProps = DllStructGetData($tProps, 3) If DllStructGetData($tProps, 2) > 0 Then If $sProps <> "" Then $aProps = StringSplit(StringTrimRight($sProps, 1), ";") EndIf Else If Not $iErr Then $iErr = 6 ;buffer overflow Return SetError($iErr, -DllStructGetData($tProps, 2), $aProps) EndIf Return $aProps EndFunc ;==>EnumProps2 Func _PropEnumProcEx2($hWnd, $sProp, $hData, $ptProp) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) If $iSzStr > 1 Then Local $sRet = DllStructGetData($tProp, 1) Local $iSzBuffer = DllStructGetData(DllStructCreate('int', $ptProp), 1) Local $tRetn = DllStructCreate('int;int;char[' & $iSzBuffer & ']', $ptProp) DllStructSetData($tRetn, 2, DllStructGetData($tRetn, 2) - $iSzStr) If DllStructGetData($tRetn, 2) > 0 Then DllStructSetData($tRetn, 3, DllStructGetData($tRetn, 3) & $sRet & ";") EndIf EndIf Return 1 EndFunc ;==>_PropEnumProcEx2
  15. Hello, Im trying to read the output from CMD using Dllcall, here is my code: #include <WinAPI.au3> #include <array.au3> Global Const $STD_OUTPUT_HANDLE = -11 Global Const $_CONSOLE_SCREEN_BUFFER_INFO = _ "struct;int dwSizeX;" & _ "short dwSizeY;" & _ "short dwCursorPositionX;" & _ "short dwCursorPositionY;" & _ "short wAttributes;" & _ "short Left;" & _ "short Top;" & _ "short Right;" & _ "short Bottom;" & _ "short dwMaximumWindowSizeX;" & _ "short dwMaximumWindowSizeY;endstruct" $pCmd = Run( "cmd.exe" ) Sleep(1000) $hCmd = WinGetHandle("") ConsoleWrite('handle:' & $hCmd & @CRLF) $aRet = DllCall("kernel32.dll", "int", "AttachConsole", "dword", $pCmd) ;_ArrayDisplay($aRet) If $aRet[0] <> 0 Then $vHandle_data='' $vHandle='' $vHandle_data = DllStructCreate($_CONSOLE_SCREEN_BUFFER_INFO) ; Screen Buffer structure $aRet1 = DllCall("kernel32.dll", "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE) if not @error Then $vHandle = $aRet1[0] $aRet = DllCall("kernel32.dll", "int", "GetConsoleScreenBufferInfo", "hwnd", $vHandle, _ "ptr", $vHandle_data) MsgBox(0, '1',DllStructGetData($vHandle_data, 'dwSizeX') & _WinAPI_GetLastErrorMessage()) EndIf It did not work, i got the message 'The handle is invalid'. Please help? Thank you in advance!
  16. So I had this Idea of creating a tooltip which shows me my ping. That itself was made quickly and I thought too add a couple features. I want the tooltip background to be a different color depending on the ping. (good ping is green, medium ping is yellow,...) So how do I color in a tooltip? google brought me to this: where in the comments I found this: $s = "LOW" ToolTip($s, 0, 0, "Battery Information");, $icon) $H_TOOLTIP1 = WinGetHandle($s) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $H_TOOLTIP1, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $H_TOOLTIP1, "int", 1043, "int", 2552550, "int", 0) Sleep(1000) Which I then used in my code with different color codes... Trial and Error brought me these that I wanted to use: The Problem is if I loop through my code it only sets the color for the 1st loop and then sticks to it. The real problem is tho that I don't exactly understand the dllcalls... And I guess that's why it isn't working So if someone would be so awesome to explain to me how they work, or at least can give me a list of these parameters then I would really appreciate that and learn something new Obviously a solution to my problem is awesome aswell ^^ I run this under Windows 8.1 There is my code in a paste. https://pastebin.com/q525f7mS
  17. Hello Guys, once aggain I need your help on a DLL Topic I need to pass arguments to my function via a structure, because I am limited to only one argument that can be passed. But I don't think that thats so important. So here's my approach: C++ Code (just the important part): extern "C" { struct ParamStruct { const char* test1; const char* test2; const char* test3; int size; }; int testFunc(struct ParamStruct * params) { return params->size; } } And thats how I try to call the function using Autoit: Local $struct = "struct;char shapefile[128];char output[128];char filename[128];int size;endstruct" Local $tTest = DllStructCreate($struct) DllStructSetData($tTest, "test1", "Bla") DllStructSetData($tTest, "test2", "BlaBla") DllStructSetData($tTest, "test3", "BlaBlaBla") DllStructSetData($tTest, "size", 40) $dll = DLLOpen("myDLL.dll") $ret = DllCall($dll, "int:cdecl", "testFunc", "STRUCT*", DllStructGetPtr($tTest)) MsgBox(0, 0, $ret[0]) DllClose($dll) Just for testing I want the function to just return the integer value in the struct. But this aint working. I tested many things, but still I'm not able to get it running. I even don't know if the mistakes are in the C++ code or the Autoit code or both .. I'm not that skilled at C++ and also not that skilled at Autoit DLLCalls :-/ I would really appreciate some help! Kind regards, leo
  18. Hello, can someone help me out with some DllCall in AU3. The relevant source of function and struct definition are as follows (in slightly modified form): typedef struct {     char    *host;     char    *key;     char    *value; } test_sender_value_t; /******************************************************************************  * Parameters: address   - [IN] server address                                *  *             port      - [IN] server port                                   *  *             source    - [IN] source IP, optional - can be NULL             *  *             values    - [IN] array of values to send                       *  *             count     - [IN] number of items in values array               *  *             result    - [OUT] the server response/error message, optional  *  *                                                                            *  * Return value: 0 - the values were sent successfully, result contains       *  *                         server response                                    *  *               -1 - an error occurred, result contains error message        *  *                                                                            *  ******************************************************************************/ TEST_API int test_sender_send_values(const char *address, unsigned short port, const char *source, const test_sender_value_t *values, int count, char **result); In AutoIt I use the following code to build the struct and call the dll: Global $struct = DllStructCreate("ptr ptrtostring1;ptr ptrtostring2;ptr ptrtostring3;") Global $string1 = DllStructCreate("char host[255];") DllStructSetData($string1, "host", "Test_Client") DllStructSetData($struct, "ptrtostring1", DllStructGetPtr($string1)) Global $string2 = DllStructCreate("char key[255];") DllStructSetData($string2, "key", "clientver") DllStructSetData($struct, "ptrtostring2", DllStructGetPtr($string2)) Global $string3 = DllStructCreate("char value[255];") DllStructSetData($string3, "value", "123456") DllStructSetData($struct, "ptrtostring3", DllStructGetPtr($string3)) Global $aCall = DllCall("C:\temp\test.dll", "int", "test_sender_send_values", _     "str", "192.168.1.2", _     "int", 80, _     "str", "192.168.1.3", _     "ptr", DllStructGetPtr($struct), _     "int", 1) If @error Then     ConsoleWrite("Error: " & @error & @CRLF)     exit 1 Else     ConsoleWrite("Success: " & $aCall[0] & @CRLF) EndIf If I ran the AU3-Script with SciTE I get the following output: !>12:00:00 AutoIt3.exe ended.rc:-1073741783 Can someone point me into the right direction. I must admit, that I'm very new to handling DLL-Calls and structs. But I've read down the forum threads and the AutoIt help. Thanks in advance.
  19. Hello, I have compiled a reference DLL in VS 2015 Community and this DLL works fine with project for which it is used. There is an interface from which u can access functions in DLL. Developers stated that this DLL is almost universal and can be used with any language with minor changes. I am trying to access its function from Autoit script and got an error 3, after calling DLLCall - "function" not found in the DLL file. Please have a quick look, I feel I miss something in C++ library with exporting functions and I do not know what to add as I am new to C++. Thank you. Source files and script also attached. Here is my script. Local $dll = DllOpen("C:\Users\Home\Desktop\dll\user.dll") ConsoleWrite("$dll handle = " & $dll & @CRLF) ;$dll handle = 1 Local $result = DllCall($dll, "double:cdecl", "ProcessQuery", "str", "dll$mynumber") If @error > 0 Then ConsoleWrite("Error: " & @error & @CRLF) ;Error = 3 If IsArray($result) Then ConsoleWrite("Array returned!" & @CRLF & "dll$mynumber: " & result[1]) Else ConsoleWrite("$result is not array. : " & $result & @CRLF) ;$result = 0 EndIf DllClose($dll) And here is dll source. As I understand, function "ProcessQuery" exported with help of DLL_IMPLEMENTS user.h //****************************************************************************** // // This file is part of the OpenHoldem project // Download page: http://code.google.com/p/openholdembot/ // Forums: http://www.maxinmontreal.com/forums/index.php // Licensed under GPL v3: http://www.gnu.org/licenses/gpl.html // //****************************************************************************** // // Purpose: Very simple user-DLL as a starting-point // // DO NOT CHANGE ANYTHING IN THIS FILE! // // This Header defines an interface // Functions and data-types must exactly match. // //****************************************************************************** #ifndef _INC_USER_H #define _INC_USER_H // Import and export directives // for use by this DLL and by OpenHoldem #ifdef USER_DLL #define DLL_IMPLEMENTS extern "C" __declspec(dllexport) #define EXE_IMPLEMENTS extern "C" __declspec(dllimport) #else #define DLL_IMPLEMENTS extern "C" __declspec(dllimport) #define EXE_IMPLEMENTS extern "C" __declspec(dllexport) #endif // Number of saved table-states // This number must not be changed, as we do a "& 0xFF" // at various places to normalize the index. const int kNumberOfHoldemStatesForDLL = 256; // SHoldemePlayer // used for sequence of 256 consequive table-states // !!!! Needs 2 more cards for Omaha, if not entirely removed struct holdem_player { char m_name[16] ; //player name if known double m_balance ; //player balance double m_currentbet ; //player current bet unsigned char m_cards[2] ; //player cards unsigned char m_name_known : 1 ; //0=no 1=yes unsigned char m_balance_known : 1 ; //0=no 1=yes unsigned char m_fillerbits : 6 ; //filler bits unsigned char m_fillerbyte ; //filler bytes }; struct holdem_state { char m_title[64] ; //table title double m_pot[10] ; //total in each pot unsigned char m_cards[5] ; //common cards unsigned char m_is_playing : 1 ; //0=sitting-out, 1=sitting-in unsigned char m_is_posting : 1 ; //0=autopost-off, 1=autopost-on unsigned char m_fillerbits : 6 ; //filler bits unsigned char m_fillerbyte ; //filler byte unsigned char m_dealer_chair ; //0-9 holdem_player m_player[10] ; //player records }; // Functions implemented and exported by the DLL, // imported by OpenHoldem DLL_IMPLEMENTS double __stdcall ProcessQuery(const char* pquery); DLL_IMPLEMENTS void __stdcall DLLOnLoad(); DLL_IMPLEMENTS void __stdcall DLLOnUnLoad(); // Functions implemented and exported by OpenHoldem, // imported by the DLL EXE_IMPLEMENTS double __stdcall GetSymbol(const char* name_of_single_symbol__not_expression); EXE_IMPLEMENTS void* __stdcall GetPrw1326(); EXE_IMPLEMENTS char* __stdcall GetHandnumber(); EXE_IMPLEMENTS void __stdcall ParseHandList(const char* name_of_list, const char* list_body); EXE_IMPLEMENTS char* __stdcall ScrapeTableMapRegion(char* p_region, int& p_returned_lengh); EXE_IMPLEMENTS void __stdcall SendChatMessage(const char *message); EXE_IMPLEMENTS void __stdcall WriteLog(char* format, ...); // Variables exported by OpenHoldem // avoiding the message-mess of WinHoldem, // no longer sending any state-messages // http://www.maxinmontreal.com/forums/viewtopic.php?f=174&t=18642 EXE_IMPLEMENTS extern holdem_state state[kNumberOfHoldemStatesForDLL]; EXE_IMPLEMENTS extern int state_index; #endif // _INC_USER_H user.cpp Here is dll$mynumber parameter. //****************************************************************************** // // This file is part of the OpenHoldem project // Download page: http://code.google.com/p/openholdembot/ // Forums: http://www.maxinmontreal.com/forums/index.php // Licensed under GPL v3: http://www.gnu.org/licenses/gpl.html // //****************************************************************************** // // Purpose: Very simple user-DLL as a starting-point // // Required OpenHoldem version: 7.7.6 // //****************************************************************************** // Needs to be defined here, before #include "user.h" // to generate proper export- and inport-definitions #define USER_DLL // #define OPT_DEMO_OUTPUT if you are a beginner // who wants to see some message-boxes with output of game-states, etc. // It is disabled upon request, // * as it is not really needed // * as some DLL-users don't have MFC (atlstr.h) installed // http://www.maxinmontreal.com/forums/viewtopic.php?f=156&t=16232 #undef OPT_DEMO_OUTPUT #include "user.h" #include <conio.h> #include <windows.h> #ifdef OPT_DEMO_OUTPUT #include <atlstr.h> #endif OPT_DEMO_OUTPUT // Supporting macros #define HIGH_NIBBLE(c) (((c)>>4)&0x0F) #define LOW_NIBBLE(c) ((c)&0x0F) // Card macro #define RANK(c) ( ISKNOWN(c) ? HIGH_NIBBLE(c) : 0 ) #define SUIT(c) ( ISKNOWN(c) ? LOW_NIBBLE(c) : 0 ) #define ISCARDBACK(c) ((c) == CARD_BACK) #define ISUNKNOWN(c) ((c) == CARD_UNDEFINED) #define ISNOCARD(c) ((c) == CARD_NOCARD) #define ISKNOWN(c) (!ISCARDBACK(c) && !ISUNKNOWN(c) && !ISNOCARD(c)) // ProcessQuery() // Handling the lookup of dll$symbols DLL_IMPLEMENTS double __stdcall ProcessQuery(const char* pquery) { if (pquery==NULL) return 0; if (strncmp(pquery,"dll$mynumber",13)==0) { return 12345.67; } return 0; } // OnLoad and OnUnload() // called once and at the beginning of a session // when the DLL gets loaded / unloaded // Do initilization / finalization here. DLL_IMPLEMENTS void __stdcall DLLOnLoad() { #ifdef OPT_DEMO_OUTPUT MessageBox(NULL, "event-load", "MESSAGE", MB_OK); #endif OPT_DEMO_OUTPUT } DLL_IMPLEMENTS void __stdcall DLLOnUnLoad() { #ifdef OPT_DEMO_OUTPUT MessageBox(NULL, "event-unload", "MESSAGE", MB_OK); #endif OPT_DEMO_OUTPUT } // DLL entry point // Technically required, but don't do anything here. // Initializations belong into the OnLoad() function, // where they get executed at run-time. // Doing things here at load-time is a bad idea, // as some functionalitz might not be properly initialized // (including error/handling). BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: #ifdef OPT_DEMO_OUTPUT AllocConsole(); #endif OPT_DEMO_OUTPUT break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; case DLL_PROCESS_DETACH: #ifdef OPT_DEMO_OUTPUT FreeConsole(); #endif OPT_DEMO_OUTPUT break; } return TRUE; } Source.zip DllAccess.au3
  20. Again, I'm struggling with DllCall(). So I have this MS C++ 6.0 compiled DLL and a manual for it. There's a function: Get information of disk arrays Declaration: VINT vr_get_array_info (VINT array_index, vr_array_info_t* pinfo); Description: Application can fetch the information of one specific disk array, which is located by index of all disk arrays in current system. Input parameters: VINT array_index : Index to all disk arrays in system, specify which disk array. vr_array_info_t *pinfo : 14 Pointer to a vr_array_info_t data structure to get the information Return value: VR_SUCCESS : Get the information successfully. VR_ERR_NOT_INITED : Raid lib hasn’t been initialized. VR_ERR_INVALID_INDEX : The input index is invalid. VR_ERR_INVALID_PARAM : Input parameter is invalid: the pointer is NULL. Here's what DLL Export Viewer says: Function Name     : int __cdecl vr_get_array_info(int,struct _vr_array_info *) Here's what is this _vr_array_info: typedef struct _vr_array_info { VWORD status; // current status of disk array VBYTE raidType;// same as Disk_Array.raidType, but value 0xFF means // a stand-alone disk. When it's a stand-alone disk, // only arDevices[0] and diskNum has meaning, and diskNum should // always be 1 . VBYTE diskNum;// count of valid arDevices[] members. // Note: disk array maybe incomplete, i.e. , some disk in the array maybe missing, // corresponding device ptr arDevices[i]->pRealDevice should be NULL. VDWORD capacityLow;// (Unit: sector) VDWORD capacityHigh;// (Unit: sector) // following 8 bytes define the real-capcity (in sector) of every disk in array VDWORD realCapacityLow; // (Unit: sector) VDWORD realCapacityHigh; // (Unit: sector) VDWORD stripeSize; // valid when raid is raid0, raid5 or raid01, in Kbytes VDWORD blockSize; // valid when raid is RAID5, in Kbytes VBOOL bNeedMigration; // the raid need migration // only valid when raid0/raid5/matrixRaid VBOOL bNeedInit; // the raid need initialization, only valid for RAID5 VBOOL bOptimized; // only for RAID5, this RAID5 access was optimized VBYTE systemDisk; /* does the devices within this disk array contain system files of current running OS ? the probably value are: VR_DEVICE_NOT_SYS_DISK VR_DEVICE_MAYBE_SYS_DISK VR_DEVICE_SYS_DISK they are defined in this file */ VWORD raid_index;// only raid index, no meaning with stand-alone disk VINT index; // all device index, including all raid and stand-alone disk } vr_array_info_t; Here's my code (function names are actually decorated, so): Local $pTest $hDLL = DllOpen(@ScriptDir & "\drvInterface.dll") ;~ VINT vr_init (void); ConsoleWrite("vr_init..." & @CRLF) $sTest = DllCall($hDLL, "int:cdecl", "?vr_init@@YAHXZ") ;~ VINT vr_get_controller_num (VINT *pnumber); ConsoleWrite("vr_get_controller_num..." & @CRLF) $sTest = DllCall($hDLL, "int:cdecl", "?vr_get_controller_num@@YAHPAH@Z", "int*", "$pTest") $iControllerNumber = $sTest[1] ConsoleWrite("$iControllerNumber = " & $iControllerNumber & @CRLF) ;~ VINT vr_get_device_num (VINT *pnumber); ConsoleWrite("vr_get_device_num..." & @CRLF) $sTest = DllCall($hDLL, "int:cdecl", "?vr_get_device_num@@YAHPAH@Z", "int*", "$pTest") $iDeviceNumber = $sTest[1] ConsoleWrite("$iDeviceNumber = " & $iDeviceNumber & @CRLF) ;~ VINT vr_get_array_num (VINT only_raid, VINT *pnumber); ConsoleWrite("vr_get_array_num..." & @CRLF) $sTest = DllCall($hDLL, "int:cdecl", "?vr_get_array_num@@YAHHPAH@Z", "int", 0, "int*", "$pTest") $iArrayNumber = $sTest[2] ConsoleWrite("$iArrayNumber = " & $iArrayNumber & @CRLF) $vr_array_info = DllStructCreate("ushort status;byte raidType;byte diskNum;dword capacityLow;dword capacityHigh;dword stripeSize;dword blockSize;boolean bNeedMigration;boolean bNeedInit;boolean bOptimized;byte systemDisk;byte raid_index;int index") ;~ VINT vr_get_array_info (VINT array_index, vr_array_info_t* pinfo); ConsoleWrite("vr_get_array_info..." & @CRLF) $sTest = DllCall($hDLL, "int:cdecl", "?vr_get_array_info@@YAHHPAU_vr_array_info@@@Z", "int", 0, "struct*", $vr_array_info) ;~ void vr_exit (void); ConsoleWrite("vr_exit..." & @CRLF) $sTest = DllCall($hDLL, "none", "?vr_exit@@YAXXZ") DllClose($hDLL) Exit Everything works fine up to vr_get_array_info part. This is where I get a "memory cannot be 'read'" Windows error ("Instruction at 0x7c93a514 referenced memory at 0x00000000"). What am I doing wrong? Please help. drvInterface.dll ProgGuide.pdf
  21. Hello! There's a DLL, which I want to use in my script. There's the manual for that DLL. I'm trying to use any function from the manual in DllCall() and I get @error=3 ("function" not found in the DLL file). Why is that? How do I fix it? PEiD says that DLL is "Microsoft Visual C++ 6.0 DLL". Is that compatible with AutoIt? How do I use it? Please help. ProgGuide.pdf drvInterface.dll
  22. Hi guys. I try to choose an algorithm to compress some string data in-memory, without file medium to store in sqlite as blob. I plan to store about 100k blobs each 80k symbols (uncompressed). First opinion was LZMA udf by Ward, but udf file doesn't exist. Then i tried to use BZIP2 dll in DllCall, but it simply doesn't work and throws @error = 1. Here is an example: What should I do with this error? Where am I wrong? Thanks.
  23. I'm attempting to call the winapi function EnumSystemFirmwareTables using DllCall "Kernel32.dll" without success. I am a total noob when it comes to this and could use some direction. Based on the documentation "Dealing with Dlls in AutoIt" by Andreas Karlsson, I have tried using the following code to obtain the buffersize of the Firmware Table Buffer. Thanks in advance for any help #include <WinAPI.au3> MsgBox(0, "ESFT BufferSize", "BufferSize = " & _EnumSystemFirmwareTables()) Func _EnumSystemFirmwareTables() $aRet = DllCall ("Kernel32.dll", "UINT", "EnumSystemFirmwareTables", "DWORD", "ACPI", "PVOID" ,Null , "DWORD" ,Null) if @error Then MsgBox (0,"Error","An error ocurred with the DLLCALL, error returned = " & @error &@CRLF & "GetLastError = " & _WinAPI_GetLastError ( ),0) Exit else Return $aRet endif EndFunc
  24. Hi friends, I'm working on a licensing project and we are using LexActicvator of Cryptlex. I'm trying to call a function of a DLL using DLLCall method. I'm calling the method 'SetProductFile' of DLL 'LexActivator_64.dll'. The parameter to the method is path to the product file and the method should return 1 on successful execution. But the method always returns 7 in my test run. #define LA_E_PFILE ((HRESULT)0x00000007L) /* CODE: LA_E_FPATH MESSAGE: Invalid product file path. */ The DLL and the product file I use are attached, please save to the script folder to test the script. Can anyone please help? I'm stuck for many days. Link to the documentation https://cryptlex.com/help/using-lexactivator #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPIReg.au3> #include <WinAPI.au3> #include<array.au3> #include <WinAPISys.au3> $sDLLPath = @ScriptDir& "\LexActivator_64.dll" ;Path to DLL file $sDataFilePath = @ScriptDir& "\Product.dat" ;Path to product data file $hDLL = DllOpen ( $sDLLPath) ;Opening DLL If $hDLL = -1 Then ;If error Msgbox(0,"Error", "Couldn't open the DLL file.") exit EndIf If Not FileExists($sDataFilePath) Then ;Checking product file Msgbox(0,"Error", "Product file does not exist.") exit EndIf $aArray = DllCall ( $hDLL , "int:cdecl", "SetProductFile", "STR", $sDataFilePath ) ;calling SetProductFile method If @error Then ;If error MsgBox(0, "Error","Error occured while calling DLL method: " & @error) Else Msgbox(0,"Result","Result received: " & $aArray[0]) ;result EndIF DllClose ( $hDLL ) LexActivator_64.dll Product.dat
  25. Hello fellas! The other night night i was converting a Msdn function to autoit and I stumbled across this topic Which inspired me like crazy and I decided to take it a step further and require the user to make almost ZERO effort to export a c++ Msdn function and or a Structure to AutoIt Shoutout to toasterking So after 18-20 effective hours: The GUI is really simple, all you need is a link to a MSDN page and the program does the rest, most of the options is just for user preferences. On the inside I have spent a decent amount of work to make sure the code come out correctly, any particular event during the conversion will get fed-back to the user, so he or she will know if anything noticeable happen. Regular DllCall example http://i.imgur.com/HZLijeu.png Struct example http://i.imgur.com/l3j6wTR.png Expand spoiler for more pictures In the "Msdn Examples" folder you will find some examples of code i have generated, in most of them I only manually added 2-3 lines to make them work. If you dont know where to get these functions you can browse the MSDN Library https://msdn.microsoft.com/en-us/library/ee663300(v=vs.85).aspx and look for any function refrence, or just google "somethingsomething msdn" and the first result will almost always contain the function you are looking for. Here is some functions you can play around with https://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms633519(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms724408(v=vs.85).aspx I would really appreciate any kind of feedback, improvements or requests If you get any type of error just post the MSDN url + the error message and ID and I will troubleshoot it. Update 0.2 Fixed some minor issues Added highlight for a more pleasent view Fixed minor bugs Made it run faster when working with the same URL (It dosent load the page entierly) No struct search is now done when no POINTER is used in the call Added more options for the user Update 0.3 Removed _IeNavigate and fixed the template for DllCall not including function name Update 0.4 Switched method to InetGet from _Ie* H0tfix3s Update 0.5 Added more options for function-layout Removed old code Added more auto detection Now using @TmpDir instead of @ScriptDir for html files etc. Update 0.6 More Output logic added Added a detection for SAL aswell, since it seems to be inconsistent according to MSDN community and myself. Better feedback on what happend with parse Code cleanup / Removed old code /Tarre DllCall and Struct Generator V 0.6.zip DllCall and Struct Generator V 0.5.zip DllCall and Struct Generator V 0.4.zip
×
×
  • Create New...