2014-07-26 07:12:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using RainmeterStudio.Interop;
|
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio
|
|
|
|
|
{
|
2014-08-12 13:33:13 +00:00
|
|
|
|
class RainmeterContext
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
#region Imports
|
|
|
|
|
|
|
|
|
|
[DllImport("Rainmeter.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
private static extern IntPtr Rainmeter_Initialize();
|
|
|
|
|
|
|
|
|
|
[DllImport("Rainmeter.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
private static extern void Rainmeter_Finalize(IntPtr handle);
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-08-12 13:33:13 +00:00
|
|
|
|
private static RainmeterContext _instance = null;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the single instance of this class
|
|
|
|
|
/// </summary>
|
2014-08-12 13:33:13 +00:00
|
|
|
|
public static RainmeterContext Instance
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_instance == null)
|
2014-08-12 13:33:13 +00:00
|
|
|
|
_instance = new RainmeterContext();
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private IntPtr _handle;
|
|
|
|
|
|
|
|
|
|
#region Constructor, finalizer
|
|
|
|
|
|
2014-08-12 13:33:13 +00:00
|
|
|
|
private RainmeterContext()
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
_handle = Rainmeter_Initialize();
|
|
|
|
|
|
|
|
|
|
if (_handle == IntPtr.Zero)
|
|
|
|
|
throw new Exception("Failed to initialize native library.");
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-12 13:33:13 +00:00
|
|
|
|
~RainmeterContext()
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
Rainmeter_Finalize(_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public IntPtr Handle { get { return _handle; } }
|
|
|
|
|
}
|
|
|
|
|
}
|