You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

424 lines
18 KiB
C#

2 years ago
using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace ocean
{
#region log
public class log
{//日志类
/****************************************************
*Function: log
*Intput: levelinfo1, info2, info3, warn error crit
pszLog
*Output: NULL
*Return: 0
******************************************************/
[DllImport(@"log.dll", EntryPoint = "traces", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int trace(ELogLevel level, string pszLog);
public static int Crit(string pszLog)
{
return trace(ELogLevel.LEVEL_CRIT, pszLog);
}
public static int Err(string pszLog)
{
return trace(ELogLevel.LEVEL_ERR, pszLog);
}
public static int Warn(string pszLog)
{
return trace(ELogLevel.LEVEL_WARN, pszLog);
}
public static int Info1(string pszLog)
{
return trace(ELogLevel.LEVEL_INFO1, pszLog);
}
public static int Info2(string pszLog)
{
return trace(ELogLevel.LEVEL_INFO2, pszLog);
}
public static int Info3(string pszLog)
{
return trace(ELogLevel.LEVEL_INFO3, pszLog);
}
#region nouse
private enum ELogLevel
{//打印级别
LEVEL_CRIT = 0,
LEVEL_ERR,
LEVEL_WARN,
LEVEL_INFO1,
LEVEL_INFO2,
LEVEL_INFO3,
LEVEL_INFO4,
};
#endregion
}
#endregion
#region config
public class config
{//配置类
[DllImport(@"config.dll", EntryPoint = "cfg_init", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int init();
[DllImport(@"config.dll", EntryPoint = "cfg_deinit", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int deinit();
/****************************************************
*Function: /-
*Intput: key [xxx]
name xxx=?
lpValue ?=xxx
*Output: NULL
*Return: 0
******************************************************/
[DllImport(@"config.dll", EntryPoint = "modify_cfg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int modify_cfg(string key, string name, string lpValue);
public static int setstr(string key, string name, string val)
{
return modify_cfg(key, name, val);
}
public static int setint(string key, string name, int val)
{
return modify_cfg(key, name, val.ToString());
}
public static int setbool(string key,string name,bool val)
{
string v = val == true ? "1" : "0";
return modify_cfg(key, name, v);
}
public static int setdouble(string key, string name, double val)
{
return modify_cfg(key, name, val.ToString());
}
/****************************************************
*Function: -
*Intput: key [xxx]
name xxx=?
index 0 5
*Output: pval
*Return: 0
******************************************************/
[DllImport(@"config.dll", EntryPoint = "get_cfgs", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_cfgs(string key, string name, StringBuilder pval);
public static string getstr(string key, string name)
{
StringBuilder pval = new StringBuilder(256);
int ret = get_cfgs(key, name, pval);
return ret == 0 ? pval.ToString() : "";
}
public static int getint(string key, string name)
{
string str = getstr(key, name);
if (str == "")
str = "0";
return Convert.ToInt32(str);
}
public static T getvalue<T>(string key, string name)
{
string va = getstr(key, name);
if (string.IsNullOrEmpty(va)) return default(T);
return (T)Convert.ChangeType(va,typeof(T));
}
public static bool getbool(string key,string name)
{
string val=getstr(key, name);
return val == "1";
}
public static double getdouble(string key, string name)
{
string str = getstr(key, name);
return str == "" ? 0.0f : Convert.ToDouble(str);
}
/****************************************************
*Function: /-data//sys.dat
*Intput: key [xxx]
name xxx=?
lpValue ?=xxx
*Output: NULL
*Return: 0
******************************************************/
[DllImport(@"config.dll", EntryPoint = "modify_sys_cfg", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int modify_sys_cfg(string key, string name, string lpValue);
public static int setsysstr(string key, string name, string val)
{
return modify_sys_cfg(key, name, val);
}
public static int setsysint(string key, string name, int val)
{
return modify_sys_cfg(key, name, val.ToString());
}
public static int setsysbool(string key, string name, bool val)
{
string v = val == true ? "1" : "0";
return modify_sys_cfg(key, name, v);
}
public static int setsysdouble(string key, string name, double val)
{
return modify_sys_cfg(key, name, val.ToString());
}
/****************************************************
*Function:
*Intput: key [xxx]
name xxx=?
index 0 5
*Output: pval
*Return: 0
******************************************************/
[DllImport(@"config.dll", EntryPoint = "get_sys_cfgs", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_sys_cfgs(string key, string name, StringBuilder pval);
public static string getsysstr(string key, string name)
{
StringBuilder pval = new StringBuilder(256);
int ret = get_sys_cfgs(key, name, pval);
return ret == 0 ? pval.ToString() : "";
}
public static int getsysint(string key, string name)
{
string str = getsysstr(key, name);
if (str == "")
str = "0";
return Convert.ToInt32(str);
}
public static T getsysvalue<T>(string key, string name)
{
string va = getsysstr(key, name);
if (string.IsNullOrEmpty(va)) return default(T);
return (T)Convert.ChangeType(va, typeof(T));
}
public static bool getsysbool(string key, string name)
{
string val = getsysstr(key, name);
return val == "1";
}
public static double getsysdouble(string key, string name)
{
string str = getsysstr(key, name);
return str == "" ? 0.0f : Convert.ToDouble(str);
}
/****************************************************
*Function:
*Intput: NULL
*Output: path 256
*Return: 0
*PS:
******************************************************/
[DllImport(@"config.dll", EntryPoint = "get_log_paths", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_log_paths(StringBuilder path);
public static string get_log_path()
{
int ret = 0;
StringBuilder p = new StringBuilder(256);
ret = get_log_paths(p);
return (0 == ret) ? p.ToString() : "";
}
/****************************************************
*Function: files_write
*Intput: file <128
pszContent <1024
npos -1
*Output:
*Return: 0
*PS:
*PS:
*PS:
******************************************************/
[DllImport(@"config.dll", EntryPoint = "files_writes", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int files_writes(string file, string pszContent, int npos = -1);
/****************************************************
*Function: NULL
*Intput: file / <128
pszContent ,
nline ,0-1
*Output:
*Return: <00
*PS:
*PS:
*PS:pszContent ,
*PS:nline=0
*PS:
******************************************************/
[DllImport(@"config.dll", EntryPoint = "files_read", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int files_read(string file, IntPtr ptr, int npos = -1);
public static string files_reads(string file, int npos = -1)
{
IntPtr ptr;
int ret = 0;
string str = "";
ptr = Marshal.AllocHGlobal(1024);
ret = files_read(file, ptr, npos);
if (ret > 0)
{
str = Marshal.PtrToStringAnsi(ptr);
}
Marshal.FreeHGlobal(ptr);
return str;
}
public static bool files_exist(string file)
{
int ret = files_read(file, IntPtr.Zero);
return ret > 0 ? true : false;
}
/****************************************************
*Function: NULL
*Intput: file / <128
pszContent ,
nline ,0-1
*Output:
*Return: <00
*PS:
*PS:
*PS:pszContent ,
*PS:nline=0
*PS:
******************************************************/
[DllImport(@"config.dll", EntryPoint = "files_close", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int files_close_all(IntPtr ptr);
public static int close_all()
{
return files_close_all(IntPtr.Zero);
}
[DllImport(@"config.dll", EntryPoint = "files_close", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int files_close(string file);
}
#endregion
#region msg
public enum MessageType
{//消息类型
MSG_NORMAL = 0, //提示消息框 -- OK
MSG_SELECT, //选择消息框 -- 是+否
MSG_RETRY, //重试消息框 -- 重试+忽略+取消 / 自定义 备用
MSG_WARN, //警告消息框 -- OK
MSG_ERR, //错误消息框 -- OK
MSG_ASCII, //字符串消息
MSG_EXITSYS, //退出系统
MSG_RESTART, //重启系统
}; //ui弹窗消息类型
public enum MessageResult
{
IDR_OK = 0, //ok
IDR_CANCEL, //取消
IDR_ABORT, //忽略
IDR_RETRY, //重试
IDR_YES, //选择是
IDR_NO, //选择否
IDR_CUS, //自定义 备用
}; //弹窗消息返回结果
//函数指针委托说明
public delegate MessageResult FunMessageShow(string pszmsg, MessageType type, IntPtr lparam);
public class msg
{//消息类
/****************************************************
*Function: ,ui
*Intput: fun
param
*Output: NULL
*Return: 0,
******************************************************/
[DllImport(@"sysapi.dll", EntryPoint = "regist_message", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int regist(FunMessageShow fun, IntPtr lparam);
/****************************************************
*Function:
*Intput: fun
*Output: NULL
*Return: 0,
*PS: 退
******************************************************/
[DllImport(@"sysapi.dll", EntryPoint = "unregist_message", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int unregist(FunMessageShow fun);
/****************************************************
*Function: UI
*Intput: type MessageType
pszmsg
*Output: NULL
*Return: (MessageResult)(<0)
*PS: 线线,线
******************************************************/
[DllImport(@"msg.dll", EntryPoint = "send_messages", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int send(MessageType type, string pszmsg);
}
#endregion
#region sys
public class sys
{//系统函数
/****************************************************
*Function:
*Intput: src
des
ext "txt or dat" --
funcall
*Output: NULL
*Return: 0,
*PS:
******************************************************/
[DllImport(@"sysapi.dll", EntryPoint = "copy_path", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int copy_path(string src, string des, IntPtr ext, IntPtr funcall);
public static int CopyPath(string src, string des)
{
return copy_path(src, des, IntPtr.Zero, IntPtr.Zero);
}
public static int CopyCsvByPath(string src, string des, string ext)
{
return copy_path(src, des, Marshal.StringToHGlobalAnsi(ext), IntPtr.Zero);
}
/****************************************************
*Function:
*Intput: pstr
count 0
*Output: NULL
*Return: double2 1, 0 EMStrType
******************************************************/
[DllImport(@"sysapi.dll", EntryPoint = "get_str_type", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
private static extern int get_str_type(string src, int count = 0);
public static bool is_number(string src) { return 1 == get_str_type(src); }
public static bool is_double(string src) { return 2 == get_str_type(src); }
public static bool is_string(string src) { return 0 == get_str_type(src); }
}
#endregion
}