using DogSetting; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace GummingBusiness { public class DogRead { public static string Read(string key, string value) { try { SoftKeyPWD ytsoftkey = new SoftKeyPWD(); //这个用于判断系统中是否存在着加密锁。不需要是指定的加密锁, string KeyPath = string.Empty; if (ytsoftkey.FindPort(0, ref KeyPath) != 0) { return string.Empty; } int id_1 = 0, id_2 = 0; if (ytsoftkey.GetID(ref id_1, ref id_2, KeyPath) != 0) { return string.Empty; } string keyid = string.Format("{0}{1}", id_1.ToString("X8"), id_2.ToString("X8")); short Version = 0; { if (ytsoftkey.NT_GetIDVersion(ref Version, KeyPath) != 0) { return string.Empty; } } //这个例子与上面的不同之处是,可以读取非固定长度的字符串,它是先从首地址读取字符串的长度,然后再读取相应的字符串 int ret; short nlen; byte[] buf = new byte[1]; string outstring = ""; short addr = 0;//要读取的地址 //先从地址0读到以前写入的字符串的长度 ret = ytsoftkey.YReadEx(buf, addr, 1, key, value, KeyPath); nlen = buf[0]; if (ret != 0) { return string.Empty; } //再读取相应长度的字符串 ret = ytsoftkey.YReadString(ref outstring, addr + 1, nlen, key, value, KeyPath); if (ret == 0) { return outstring; } return string.Empty; } catch { return string.Empty; } } } }