Skip to content
Snippets Groups Projects

RunVoicemeeter

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Jan Henrik
    Edited
    voicemeeter.cpp 1.94 KiB
    std::string QueryRegistry(std::string path, std::string key) {
    #ifndef KEY_WOW64_32KEY
        #define KEY_WOW64_32KEY 0x0200
    #endif
        constexpr DWORD NO_OPTIONS = 0;
        HKEY handle;
        long result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), NO_OPTIONS, KEY_READ, &handle);
        if(result != ERROR_SUCCESS) {
            result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, path.c_str(), NO_OPTIONS, KEY_READ | KEY_WOW64_32KEY, &handle);
            if(result != ERROR_SUCCESS) {
                throw (unsigned long)result;
            }
        }
        DWORD required_size = 0;
        // buffer of nullptr writes the size of the data in the size parameter
        RegQueryValueEx(handle, key.c_str(), nullptr, nullptr, nullptr, &required_size);
        DWORD value_type, buffer_size = required_size;
        std::vector<char> buffer(buffer_size);
        result = RegQueryValueEx(handle, key.c_str(), nullptr, &value_type, (BYTE*)buffer.data(), &buffer_size);
        if(result != ERROR_SUCCESS) {
            throw (unsigned long)result;
        }
        return std::string(buffer.data(), buffer_size);
    }
    
    std::string parent_path(std::string path) {
        const char delimiter = '\\';
        using it = std::string::iterator;
        it begin = path.begin(), end = path.begin();
        it current = path.begin();
        while(current != path.end()) {
            if(*current == delimiter)
                end = current;
            ++current;
        }
        return {begin, end};
    }
    
    std::string VoicemeeterInstallPath() {
        const std::string key = R"(SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\VB:Voicemeeter {17359A74-1236-5467})";
        std::string path = QueryRegistry(key, "UninstallString");
        return parent_path(path);
    }
    
    void RunExe(std::string exe, std::string working_dir) {
        ShellExecuteA(nullptr, "open", exe.c_str(), working_dir.c_str(), working_dir.c_str(), SW_SHOW);
    }
    
    void RunVoicemeeter() {
        std::string install_path = VoicemeeterInstallPath();
        std::string exe = install_path + "\\voicemeeterpro.exe";
        RunExe(exe, install_path);
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment