#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: gritts Script Function: Not the most elegant of scripts. Written to learn how to execute DLLCalls against the VoiceMeeter .dll. The end goal is to capture active settings of VoiceMeeter then be able to restore then with the click of a button or running of a script. This version I'm posting for others to use as a reference. I plan to build on this and improve as time and ideas coinside. Tested against VoicemeeterPotato. I'm certain it can be adapted for Voicemeeter and VoiceMeeter Banana For thread reference: https://www.autoitscript.com/forum/topic/208121-unable-to-use-the-dll-file-error-when-executing-a-dllcall Thanks to "TheXman", "Danyfirex" for helping me better understand translating the VoiceMeeter API header file to something sensible that works in AutoIt. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #AutoIt3Wrapper_UseX64=y #include #include ;ProcessWait("voicemeeter8.exe") ;comented out, not sure if this is needed ;Tinkering with an idea. More of a notice that would appear in CUI If Not FileExists(@ScriptDir & "\VM_Settings.ini") Then ConsoleWrite("No previous settings file found, new one will be created" & @CRLF) EndIf ;Ask the user if they wish to save a new config (overwrite existing settings) $res = MsgBox(36, "Question", "Do you wish to save a new config?") If $res = $IDYES Then ;This will use "VBVMR_GetParameterFloat" to retrieve several values and save to .INI MsgBox(0, "Answer", "Yes was pushed") $saveini = "y" ElseIf $res = $IDNO Then ;This will use "VBVMR_SetParameterFloat" to reset values previously saved to .INI MsgBox(0, "Answer", "No was pushed") $saveini = "n" EndIf ; Open DLL Local $hDll = DllOpen("C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll") If @error Then ConsoleWriteError('Error DllOpen: ' & ' Error: ' & @error & ' Extended: ' & @extended & @CR) EndIf ; Call login function VBVMR_Login($hDll) ; Call IsParameterDirty function (Not using hear, present for learning) $sDirty = VBVMR_IsParametersDirty($hDll) ConsoleWrite("Is Dirty: " & $sDirty & @CRLF) ; Call voicemeeter type function (Not using hear, present for learning) $sType = VBVMR_GetVoicemeeterType($hDll) ConsoleWrite("VM type: " & $sType & @CRLF) ;Call voicemeeter version function (Not using hear, present for learning) VBVMR_GetVoicemeeterVersion($hDll) ; Test getting status (more robust value retrieval) $sParam = "Strip[1].A1" $fValue = VBVMR_GetParameterFloat($hDll, $sParam) If @error Then MsgBox($MB_ICONWARNING + $MB_TOPMOST, "ERROR", _ "VBVMR_GetParameterFloat error occurred." & @LF & @LF & _ "@error = " & @error & @LF & _ "@extended = " & @extended) Exit EndIf ConsoleWrite("Results: " & $sParam & " - " & $fValue & @CRLF) ;The following If statement is ugly. I believe this can be accomplished more neatly with IniWriteSection and an Array If $saveini = "y" Then ;When user selects to capture settings again IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].Mute", VBVMR_GetParameterFloat($hDll, "Strip[0].Mute")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B1", VBVMR_GetParameterFloat($hDll, "Strip[0].B1")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B2", VBVMR_GetParameterFloat($hDll, "Strip[0].B2")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B3", VBVMR_GetParameterFloat($hDll, "Strip[0].B3")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[0].Gain", VBVMR_GetParameterFloat($hDll, "Bus[0].Gain")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[1].Gain", VBVMR_GetParameterFloat($hDll, "Bus[1].Gain")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[2].Gain", VBVMR_GetParameterFloat($hDll, "Bus[2].Gain")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[5].A1", VBVMR_GetParameterFloat($hDll, "Strip[5].A1")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[6].A1", VBVMR_GetParameterFloat($hDll, "Strip[6].A1")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A1", VBVMR_GetParameterFloat($hDll, "Strip[7].A1")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[5].A2", VBVMR_GetParameterFloat($hDll, "Strip[5].A2")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[6].A2", VBVMR_GetParameterFloat($hDll, "Strip[6].A2")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A2", VBVMR_GetParameterFloat($hDll, "Strip[7].A2")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[5].A3", VBVMR_GetParameterFloat($hDll, "Strip[5].A3")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[6].A3", VBVMR_GetParameterFloat($hDll, "Strip[6].A3")) IniWrite(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A3", VBVMR_GetParameterFloat($hDll, "Strip[7].A3")) ElseIf $saveini = "n" Then ;When user selects to restore previous settings VBVMR_SetParameterFloat($hDll, "Strip[0].Mute", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].Mute", "")) VBVMR_SetParameterFloat($hDll, "Strip[0].B1", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B1", "")) VBVMR_SetParameterFloat($hDll, "Strip[0].B2", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B2", "")) VBVMR_SetParameterFloat($hDll, "Strip[0].B3", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[0].B3", "")) VBVMR_SetParameterFloat($hDll, "Bus[0].Gain", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[0].Gain", "")) VBVMR_SetParameterFloat($hDll, "Bus[1].Gain", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[1].Gain", "")) VBVMR_SetParameterFloat($hDll, "Bus[2].Gain", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Bus[2].Gain", "")) VBVMR_SetParameterFloat($hDll, "Strip[5].A1", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[5].A1","")) VBVMR_SetParameterFloat($hDll, "Strip[6].A1", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[6].A1", "")) VBVMR_SetParameterFloat($hDll, "Strip[7].A1", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A1", "")) VBVMR_SetParameterFloat($hDll, "Strip[5].A2", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[5].A2", "")) VBVMR_SetParameterFloat($hDll, "Strip[6].A2", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[6].A2", "")) VBVMR_SetParameterFloat($hDll, "Strip[7].A2", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A2", "")) VBVMR_SetParameterFloat($hDll, "Strip[7].A3", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A3", "")) VBVMR_SetParameterFloat($hDll, "Strip[7].A3", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A3", "")) VBVMR_SetParameterFloat($hDll, "Strip[7].A3", IniRead(@ScriptDir & "\VM_Settings.ini", "Test", "Strip[7].A3", "")) EndIf ;Test changing value ; Use results of GetParameterFloat to determine what to set parameter to ;~ If $fValue = "1" Then ;~ ConsoleWrite("It is active, setting to inactive" & @CRLF) ;~ VBVMR_SetParameterFloat($hDll, $sParam, "0") ;~ ElseIf $fValue = "0" Then ;~ ConsoleWrite("It is inactive setting to active" & @CRLF) ;~ VBVMR_SetParameterFloat($hDll, $sParam, "1") ;~ EndIf ; Testing retreival of color parameters $sParam = "Strip[1].Color_y" $fValue = VBVMR_GetParameterFloat($hDll, $sParam) If @error Then MsgBox($MB_ICONWARNING + $MB_TOPMOST, "ERROR", _ "VBVMR_GetParameterFloat error occurred." & @LF & @LF & _ "@error = " & @error & @LF & _ "@extended = " & @extended) Exit EndIf ConsoleWrite("Results: " & StringFormat("%-27s = %+0.2f", $sParam, $fValue) & @CRLF) ; Testing retreival of color parameters $sParam = "Strip[1].Color_x" $fValue = VBVMR_GetParameterFloat($hDll, $sParam) If @error Then MsgBox($MB_ICONWARNING + $MB_TOPMOST, "ERROR", _ "VBVMR_GetParameterFloat error occurred." & @LF & @LF & _ "@error = " & @error & @LF & _ "@extended = " & @extended) Exit EndIf ConsoleWrite("Results: " & StringFormat("%-27s = %+0.2f", $sParam, $fValue) & @CRLF) ; Testing retreival of gain parameters $sParam = "Strip[1].Gain" $fValue = VBVMR_GetParameterFloat($hDll, $sParam) If @error Then MsgBox($MB_ICONWARNING + $MB_TOPMOST, "ERROR", _ "VBVMR_GetParameterFloat error occurred." & @LF & @LF & _ "@error = " & @error & @LF & _ "@extended = " & @extended) Exit EndIf ConsoleWrite("Results: " & StringFormat("%-27s = %+0.2f", $sParam, $fValue) & @CRLF) ; Call logout function VBVMR_Logout($hDll) ; Close DLL DllClose($hDll) ; ========= Functions follow ------------- Func VBVMR_GetParameterFloat($apiDLL, $sParamName) Local $aResult ;Call API $aResult = DllCall($apiDLL, "long", "VBVMR_GetParameterFloat", _ "str", $sParamName, _ "float*", 0) If @error Then Return SetError(-99, @error, -99.0) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, -99.0) ;_ArrayDisplay($aResult) Return $aResult[2] EndFunc ;==>VBVMR_GetParameterFloat Func VBVMR_SetParameterFloat($apiDLL, $sParamName, $sVal) Local $aResult ;Call API $aResult = DllCall($apiDLL, "long", "VBVMR_SetParameterFloat", _ "str", $sParamName, _ "float*", $sVal) If @error Then Return SetError(-99, @error, -99.0) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, -99.0) Sleep(50) ;_ArrayDisplay($aResult) Return $aResult[2] EndFunc ;==>VBVMR_SetParameterFloat Func VBVMR_Login($apiDLL) ; Login to the DLL Local $aResult $aResult = DllCall($apiDLL, "long", "VBVMR_Login") If @error Then Return SetError(-99, @error, -99.0) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, -99.0) Sleep(250) EndFunc ;==>VBVMR_Login Func VBVMR_IsParametersDirty($apiDLL) Local $aResult ; Check parameter status $aResult = DllCall($apiDLL, "long", "VBVMR_IsParametersDirty") ConsoleWrite("Filth: " & $aResult[0] & @CRLF) If @error Then Return SetError(-99, @error, -99.0) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, -99.0) EndFunc ;==>VBVMR_IsParametersDirty Func VBVMR_Logout($apiDLL) Local $aResult ; Logout of DLL $aResult = DllCall($apiDLL, "long", "VBVMR_Logout") If @error Then Return SetError(-99, @error, -99.0) If $aResult[0] <> 0 Then Return SetError($aResult[0], 0, -99.0) EndFunc ;==>VBVMR_Logout Func VBVMR_GetVoicemeeterType($apiDLL) Local $aResult $aResult = DllCall($apiDLL, "long", "VBVMR_GetVoicemeeterType", "int*", 0) If @error Then ConsoleWriteError('Error VBVMR_GetVoicemeeterType: ' & ' Error: ' & @error & ' Extended: ' & @extended & @CR) EndIf ;_ArrayDisplay($aResult) ConsoleWrite("Voicemeeter type: " & $aResult[1] & @CRLF) Select Case $aResult[1] = "1" Return ("Voicemeeter") Case $aResult[1] = "2" Return ("Voicemeeter Banana") Case $aResult[1] = "3" Return ("Voicemeeter Potato") Case Else Return ("Unknown Type") EndSelect EndFunc ;==>VBVMR_GetVoicemeeterType Func VBVMR_GetVoicemeeterVersion($apiDLL) Local $aResult, $dBinary Local $sVMVer = "" $aResult = DllCall($apiDLL, "long", "VBVMR_GetVoicemeeterVersion", "long*", 0) If @error Then ConsoleWriteError('Error VBVMR_GetVoicemeeterVersion: ' & ' Error: ' & @error & ' Extended: ' & @extended & @CR) EndIf ConsoleWrite("$aResult[1]: " & $aResult[1] & @CRLF) ConsoleWrite("Binary: " & Binary($aResult[1]) & @CRLF) ConsoleWrite("BinaryMid: " & String(Dec(Int(BinaryMid($aResult[1], 4, 1)))) & @CRLF) For $i = 4 To 1 Step -1 If $i > 1 Then $sVMVer &= String(Dec(Int(BinaryMid($aResult[1], $i, 1)))) & "." Else $sVMVer &= String(Dec(Int(BinaryMid($aResult[1], $i, 1)))) EndIf Next ConsoleWrite("Derived version: " & $sVMVer & @CRLF) EndFunc ;==>VBVMR_GetVoicemeeterVersion