Use PortAudio-Sharp bindings for easier updates
Use COSFunctions for OS-specific stuff Add dll directories on startup (could be done in the modules itself, but this way it avoids all trouble)
This commit is contained in:
1 parent
f0fca0baf7
commit
5316d30a7d
12 files changed
+196
-650
No files matched your search
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Vocaluxe
|
||||
{
|
||||
static class COSFunctions
|
||||
{
|
||||
#if WIN
|
||||
private static bool _DefaultDllDirSet;
|
||||
private static bool _UsePath;
|
||||
private static bool _UseSetDllDir;
|
||||
|
||||
private static class CWindowsFunctions
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void AddDllDirectory(string lpPathName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void SetDllDirectory(string lpPathName);
|
||||
|
||||
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetDefaultDllDirectories(int directoryFlags);
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
public const int LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000;
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void AddEnvironmentPath(string path)
|
||||
{
|
||||
string newPath = Environment.GetEnvironmentVariable("PATH") ?? string.Empty;
|
||||
if (newPath.Length > 0)
|
||||
newPath += ";";
|
||||
newPath += path;
|
||||
|
||||
Environment.SetEnvironmentVariable("PATH", newPath);
|
||||
}
|
||||
|
||||
public static void AddLibrarySearchpath(string path)
|
||||
{
|
||||
#if WIN
|
||||
if (!_DefaultDllDirSet)
|
||||
{
|
||||
try
|
||||
{
|
||||
CWindowsFunctions.SetDefaultDllDirectories(CWindowsFunctions.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_UsePath = true;
|
||||
_UseSetDllDir = true;
|
||||
}
|
||||
_DefaultDllDirSet = true;
|
||||
}
|
||||
if (_UsePath)
|
||||
AddEnvironmentPath(path);
|
||||
if (!_UseSetDllDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
CWindowsFunctions.AddDllDirectory(path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_UseSetDllDir = true;
|
||||
}
|
||||
}
|
||||
if (_UseSetDllDir)
|
||||
CWindowsFunctions.SetDllDirectory(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void SetForegroundWindow(IntPtr hWnd)
|
||||
{
|
||||
#if WIN
|
||||
CWindowsFunctions.SetForegroundWindow(hWnd);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user