参考vnr调用的方法:

https://github.com/Artikash/VNR-Core/blob/6ed038bda9dcd35696040bd45d31afa6a30e8978/py/libs/jbeijing/jbjct.py

使用JBeijing目录下的JBJCT.dll:

 [DllImport(@"D:\jBeijingV7\JBJCT.dll", CharSet = CharSet.Unicode,CallingConvention = CallingConvention.Cdecl)]
 public static extern int JC_Transfer_Unicode( 
        int hwnd, 
        uint fromCordPage,
        uint toCodePage,
        int unknown,
        int unknown2,  
        string from, 
        StringBuilder to,
        ref int toCapacity, 
        StringBuilder buffer,
        ref int bufferCapacity
 );

使用例子:

static void Main(string[] args)
        {
            string originalText = "必死に生きてこそ、その人生は光を放つ.";
            StringBuilder outText = new StringBuilder(originalText.Length * 10);
StringBuilder outText buff=new StringBuilder(originalText.Length * 10);
            var toCapacity = outText.Capacity;
            var bufferCapacity = buff.Capacity;
            JC_Transfer_Unicode(
                0,
                932,
                936,         //繁体950
                1,
                1,
                originalText,//待翻译文本
                outText,     //译文
                ref toCapacity,
                buff,
                ref bufferCapacity
                );
            Console.WriteLine(outText);
            Console.ReadKey();
        }

运行结果:

如果要使用自定义词库,使用DJC_OpenAllUserDic_Unicode函数,最多支持3个词库,返回1或者-255 成功,不再使用词库使用

[DllImport(@"D:\gal\jBeijingV7\JBJCT.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
        public static extern int DJC_OpenAllUserDic_Unicode(byte[] userdict, int unknown=0);

[DllImport(@"D:\gal\jBeijingV7\JBJCT.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int DJC_CloseAllUserDic(int unknown=1);

使用例子:

const int DictSize = 0x408;//1032 词库路径最大字节数
const int MaxDictCount = 3;  //最大支持3个词库
readonly int Dictbuffer = DictSize * MaxDictCount;//总字节数
string user1 = @"C:\Users\Desktop\[191213]JcU\JcUserdic\Jcuser";
public bool OpenUserDic(params string[] path)
        {
            if (path.Length > 3||path.Length==0)return false;
            var buffer = new Byte[Dictbuffer];
            for (var i = 0; i < path.Length; ++i)
            {
                byte[] byteArray = Encoding.Unicode.GetBytes(path[i]);
                Array.Copy(byteArray, 0, buffer, i * DictSize, byteArray.Length);
            }
            var res= DJC_OpenAllUserDic_Unicode(buffer);
            if (res == 1 || res == -255) return true; //1或者-255 成功
            return false;
        }


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。