2024-07-06 09:03:13 +01:00
|
|
|
/**
|
|
|
|
* @file ivmr.c
|
|
|
|
* @author Vincent Burel, Onyx and Iris (code@onyxandiris.online)
|
|
|
|
* @brief Functions for initializing the iVMR interface.
|
|
|
|
* Defines a single public function that returns a pointer to the interface.
|
2024-07-09 13:14:52 +01:00
|
|
|
* @version 0.7.0
|
2024-07-06 09:03:13 +01:00
|
|
|
* @date 2024-07-06
|
|
|
|
*
|
|
|
|
* @copyright Vincent Burel(c)2015-2021 All Rights Reserved
|
2024-07-06 09:36:33 +01:00
|
|
|
* https://github.com/vburel2018/Voicemeeter-SDK/blob/main/LICENSE
|
2024-07-06 09:03:13 +01:00
|
|
|
*
|
2024-07-06 09:36:33 +01:00
|
|
|
* Copyright (c) 2024 Onyx and Iris
|
2024-07-06 09:03:13 +01:00
|
|
|
* https://github.com/onyx-and-iris/vmrcli/blob/main/LICENSE
|
|
|
|
*/
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2024-07-03 13:57:58 +01:00
|
|
|
#include <windows.h>
|
2024-07-06 09:03:13 +01:00
|
|
|
#include "ivmr.h"
|
2024-06-28 03:21:38 +01:00
|
|
|
#include "util.h"
|
2024-07-05 10:41:07 +01:00
|
|
|
#include "log.h"
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-05 10:41:07 +01:00
|
|
|
static T_VBVMR_INTERFACE iVMR;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-05 10:41:07 +01:00
|
|
|
static long initialize_dll_interfaces(PT_VMR vmr);
|
|
|
|
static bool registry_get_voicemeeter_folder(char *szDir);
|
2024-06-25 17:22:33 +01:00
|
|
|
|
2024-07-06 09:03:13 +01:00
|
|
|
/**
|
|
|
|
* @brief Create an interface object
|
|
|
|
*
|
|
|
|
* @return PT_VMR Pointer to the iVMR interface
|
|
|
|
*/
|
2024-07-05 10:41:07 +01:00
|
|
|
PT_VMR create_interface()
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-05 10:41:07 +01:00
|
|
|
PT_VMR vmr = &iVMR;
|
|
|
|
int rep;
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-05 10:41:07 +01:00
|
|
|
rep = initialize_dll_interfaces(vmr);
|
|
|
|
if (rep < 0)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-07-05 10:41:07 +01:00
|
|
|
if (rep == -100)
|
|
|
|
{
|
|
|
|
log_fatal("Voicemeeter is not installed");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
log_fatal("Error loading Voicemeeter dll with code %d\n", rep);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
2024-07-05 10:41:07 +01:00
|
|
|
return vmr;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/** GET DLL INTERFACE **/
|
|
|
|
/*******************************************************************************/
|
2024-07-05 10:41:07 +01:00
|
|
|
static long initialize_dll_interfaces(PT_VMR vmr)
|
2024-06-25 04:34:28 +01:00
|
|
|
{
|
2024-06-25 17:22:33 +01:00
|
|
|
HMODULE G_H_Module = NULL;
|
2024-06-25 04:34:28 +01:00
|
|
|
char szDllName[1024];
|
2024-07-04 09:14:14 +01:00
|
|
|
memset(vmr, 0, sizeof(T_VBVMR_INTERFACE));
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-06-25 17:22:33 +01:00
|
|
|
// get Voicemeeter installation directory
|
2024-06-25 04:34:28 +01:00
|
|
|
if (!registry_get_voicemeeter_folder(szDllName))
|
|
|
|
{
|
2024-06-25 17:22:33 +01:00
|
|
|
// Voicemeeter not installed
|
2024-06-25 04:34:28 +01:00
|
|
|
return -100;
|
|
|
|
}
|
2024-06-25 17:22:33 +01:00
|
|
|
// use right dll according to O/S type
|
2024-06-25 04:34:28 +01:00
|
|
|
if (sizeof(void *) == 8)
|
|
|
|
strcat(szDllName, "\\VoicemeeterRemote64.dll");
|
|
|
|
else
|
|
|
|
strcat(szDllName, "\\VoicemeeterRemote.dll");
|
|
|
|
|
|
|
|
// Load Dll
|
|
|
|
G_H_Module = LoadLibrary(szDllName);
|
|
|
|
if (G_H_Module == NULL)
|
|
|
|
return -101;
|
|
|
|
|
|
|
|
// Get function pointers
|
2024-07-04 09:14:14 +01:00
|
|
|
vmr->VBVMR_Login = (T_VBVMR_Login)GetProcAddress(G_H_Module, "VBVMR_Login");
|
|
|
|
vmr->VBVMR_Logout = (T_VBVMR_Logout)GetProcAddress(G_H_Module, "VBVMR_Logout");
|
|
|
|
vmr->VBVMR_RunVoicemeeter = (T_VBVMR_RunVoicemeeter)GetProcAddress(G_H_Module, "VBVMR_RunVoicemeeter");
|
|
|
|
vmr->VBVMR_GetVoicemeeterType = (T_VBVMR_GetVoicemeeterType)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterType");
|
|
|
|
vmr->VBVMR_GetVoicemeeterVersion = (T_VBVMR_GetVoicemeeterVersion)GetProcAddress(G_H_Module, "VBVMR_GetVoicemeeterVersion");
|
|
|
|
|
|
|
|
vmr->VBVMR_IsParametersDirty = (T_VBVMR_IsParametersDirty)GetProcAddress(G_H_Module, "VBVMR_IsParametersDirty");
|
|
|
|
vmr->VBVMR_GetParameterFloat = (T_VBVMR_GetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_GetParameterFloat");
|
|
|
|
vmr->VBVMR_GetParameterStringA = (T_VBVMR_GetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringA");
|
|
|
|
vmr->VBVMR_GetParameterStringW = (T_VBVMR_GetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_GetParameterStringW");
|
|
|
|
vmr->VBVMR_GetLevel = (T_VBVMR_GetLevel)GetProcAddress(G_H_Module, "VBVMR_GetLevel");
|
|
|
|
vmr->VBVMR_GetMidiMessage = (T_VBVMR_GetMidiMessage)GetProcAddress(G_H_Module, "VBVMR_GetMidiMessage");
|
|
|
|
|
|
|
|
vmr->VBVMR_SetParameterFloat = (T_VBVMR_SetParameterFloat)GetProcAddress(G_H_Module, "VBVMR_SetParameterFloat");
|
|
|
|
vmr->VBVMR_SetParameters = (T_VBVMR_SetParameters)GetProcAddress(G_H_Module, "VBVMR_SetParameters");
|
|
|
|
vmr->VBVMR_SetParametersW = (T_VBVMR_SetParametersW)GetProcAddress(G_H_Module, "VBVMR_SetParametersW");
|
|
|
|
vmr->VBVMR_SetParameterStringA = (T_VBVMR_SetParameterStringA)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringA");
|
|
|
|
vmr->VBVMR_SetParameterStringW = (T_VBVMR_SetParameterStringW)GetProcAddress(G_H_Module, "VBVMR_SetParameterStringW");
|
|
|
|
|
|
|
|
vmr->VBVMR_Output_GetDeviceNumber = (T_VBVMR_Output_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceNumber");
|
|
|
|
vmr->VBVMR_Output_GetDeviceDescA = (T_VBVMR_Output_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescA");
|
|
|
|
vmr->VBVMR_Output_GetDeviceDescW = (T_VBVMR_Output_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Output_GetDeviceDescW");
|
|
|
|
vmr->VBVMR_Input_GetDeviceNumber = (T_VBVMR_Input_GetDeviceNumber)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceNumber");
|
|
|
|
vmr->VBVMR_Input_GetDeviceDescA = (T_VBVMR_Input_GetDeviceDescA)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescA");
|
|
|
|
vmr->VBVMR_Input_GetDeviceDescW = (T_VBVMR_Input_GetDeviceDescW)GetProcAddress(G_H_Module, "VBVMR_Input_GetDeviceDescW");
|
2024-06-25 04:34:28 +01:00
|
|
|
|
2024-07-04 12:19:04 +01:00
|
|
|
vmr->VBVMR_MacroButton_IsDirty = (T_VBVMR_MacroButton_IsDirty)GetProcAddress(G_H_Module, "VBVMR_MacroButton_IsDirty");
|
|
|
|
vmr->VBVMR_MacroButton_GetStatus = (T_VBVMR_MacroButton_GetStatus)GetProcAddress(G_H_Module, "VBVMR_MacroButton_GetStatus");
|
|
|
|
vmr->VBVMR_MacroButton_SetStatus = (T_VBVMR_MacroButton_SetStatus)GetProcAddress(G_H_Module, "VBVMR_MacroButton_SetStatus");
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
// check pointers are valid
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Login == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -1;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Logout == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -2;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_RunVoicemeeter == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -2;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetVoicemeeterType == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -3;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetVoicemeeterVersion == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -4;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_IsParametersDirty == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -5;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetParameterFloat == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -6;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetParameterStringA == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -7;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetParameterStringW == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -8;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetLevel == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -9;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_SetParameterFloat == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -10;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_SetParameters == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -11;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_SetParametersW == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -12;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_SetParameterStringA == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -13;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_SetParameterStringW == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -14;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_GetMidiMessage == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -15;
|
|
|
|
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Output_GetDeviceNumber == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -30;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Output_GetDeviceDescA == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -31;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Output_GetDeviceDescW == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -32;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Input_GetDeviceNumber == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -33;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Input_GetDeviceDescA == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -34;
|
2024-07-04 09:14:14 +01:00
|
|
|
if (vmr->VBVMR_Input_GetDeviceDescW == NULL)
|
2024-06-25 04:34:28 +01:00
|
|
|
return -35;
|
|
|
|
|
2024-07-04 12:19:04 +01:00
|
|
|
if (vmr->VBVMR_MacroButton_IsDirty == NULL)
|
|
|
|
return -36;
|
|
|
|
if (vmr->VBVMR_MacroButton_GetStatus == NULL)
|
|
|
|
return -37;
|
|
|
|
if (vmr->VBVMR_MacroButton_SetStatus == NULL)
|
|
|
|
return -38;
|
|
|
|
|
2024-06-25 04:34:28 +01:00
|
|
|
return 0;
|
2024-07-05 10:41:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
/** GET VOICEMEETER DIRECTORY **/
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#define INSTALLER_UNINST_KEY "VB:Voicemeeter {17359A74-1236-5467}"
|
|
|
|
|
|
|
|
#ifndef KEY_WOW64_32KEY
|
|
|
|
#define KEY_WOW64_32KEY 0x0200
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool registry_get_voicemeeter_folder(char *szDir)
|
|
|
|
{
|
|
|
|
char szKey[256];
|
|
|
|
char sss[1024];
|
|
|
|
DWORD nnsize = 1024;
|
|
|
|
HKEY hkResult;
|
|
|
|
LONG rep;
|
|
|
|
DWORD pptype = REG_SZ;
|
|
|
|
sss[0] = 0;
|
|
|
|
const char uninstDirKey[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
|
|
|
|
|
|
|
|
// build Voicemeeter uninstallation key
|
|
|
|
strcpy(szKey, uninstDirKey);
|
|
|
|
strcat(szKey, "\\");
|
|
|
|
strcat(szKey, INSTALLER_UNINST_KEY);
|
|
|
|
|
|
|
|
// open key
|
|
|
|
rep = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ, &hkResult);
|
|
|
|
if (rep != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
// if not present we consider running in 64bit mode and force to read 32bit registry
|
|
|
|
rep = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_READ | KEY_WOW64_32KEY, &hkResult);
|
|
|
|
}
|
|
|
|
if (rep != ERROR_SUCCESS)
|
|
|
|
return false;
|
|
|
|
// read uninstall path from registry
|
|
|
|
rep = RegQueryValueEx(hkResult, "UninstallString", 0, &pptype, (unsigned char *)sss, &nnsize);
|
|
|
|
RegCloseKey(hkResult);
|
|
|
|
|
|
|
|
if (pptype != REG_SZ)
|
|
|
|
return false;
|
|
|
|
if (rep != ERROR_SUCCESS)
|
|
|
|
return false;
|
|
|
|
// remove name to get the path only
|
2024-07-08 16:01:14 +01:00
|
|
|
remove_last_part_of_path(sss);
|
2024-07-05 10:41:07 +01:00
|
|
|
if (nnsize > 512)
|
|
|
|
nnsize = 512;
|
|
|
|
strncpy(szDir, sss, nnsize);
|
|
|
|
|
|
|
|
return true;
|
2024-06-25 04:34:28 +01:00
|
|
|
}
|