Source

SharpHammer / SharpHammer / core.cs

Full commit
using System;
using System.Security;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace SharpHammer
{
	#region log

	public enum log_type
	{
		Text = 0,
		Error = 1,
		Warning = 2,
		Info = 3,
		Load = 4
	}

	[StructLayout(LayoutKind.Sequential)]
	public struct log_stats
	{
		public UInt32 msgs_cnt;
		public UInt32 errors_cnt;
		public UInt32 warnings_cnt;
	}

	#endregion

	#region error_codes
	public enum result_t
	{
		RET_ABORT = 2,
		RET_OK = 1,
		RET_FAIL = 0,
		RET_OUTOFMEMORY = -1,
		RET_WARNING = -2,
		RET_INVALIDARG = -3,
		RET_FILE_ERROR = -4,
		RET_NOT_IMPL = -5,
		RET_NOT_SUPPORTED = -6,
		RET_INVALIDCALL = -7
	}
	#endregion

	[SuppressUnmanagedCodeSecurity]
	public class core
	{
		public const string NativeDll = "dh_core.dll";

		#region core
		// core_init
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t core_init(
			[MarshalAs(UnmanagedType.Bool)] bool trace_mem);

		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern void core_release(
			[MarshalAs(UnmanagedType.Bool)] bool report_leaks);

		#endregion

		#region log
		// pfn_log_handler
		public delegate void pfn_log_handler(log_type param0,
			[In] [MarshalAs(UnmanagedType.LPStr)] string param1, IntPtr param2);

		// log_outputconsole
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t log_outputconsole(
			[MarshalAs(UnmanagedType.Bool)]bool enable);
		// log_outputfile
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t log_outputfile(
			[MarshalAs(UnmanagedType.Bool)]bool enable,
			[In] [MarshalAs(UnmanagedType.LPStr)] string log_filepath);
		// log_outputdebugger
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t log_outputdebugger(
			[MarshalAs(UnmanagedType.Bool)]bool enable);
		// log_outputfunc
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t log_outputfunc(uint enable,
			pfn_log_handler log_fn, IntPtr param);
		// log_isconsole
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool log_isconsole();
		// log_isfile
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool log_isfile();
		// log_isdebugger
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool log_isdebugger();
		// log_isoutputfunc
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		[return: MarshalAs(UnmanagedType.Bool)]
		public static extern bool log_isoutputfunc();
		// log_print
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern void log_print(log_type type,
			[In] [MarshalAs(UnmanagedType.LPStr)] string text);
		// log_getstats
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern void log_getstats(ref log_stats stats);
		// log_init
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern result_t log_init();
		// log_release
		[DllImport(core.NativeDll, CallingConvention = CallingConvention.Cdecl)]
		public static extern void Release();
		#endregion

	}
}