金山快译是一款支持中英日互译的离线翻译软件,尝试用c#调用。
参考vnr的调用方法:
调用GTS目录下的相应dll,以日中翻译为例:
const string FASTAIT_DLL =@"C:\Kingsoft\FASTAIT_PERSONAL\GTS\JapaneseSChinese\JPNSCHSDK.dll";
const string PATH = @"C:\Kingsoft\FASTAIT_PERSONAL\GTS\JapaneseSChinese\";
const string DEFAULT_DIC = "DCT";
int buffersize = 0x4f4;
int key = 0x4f4;
[DllImport(FASTAIT_DLL)]
internal static extern int StartSession(
[MarshalAs(UnmanagedType.LPWStr)] string dicpath,
IntPtr bufferStart,
IntPtr bufferStop,
[MarshalAs(UnmanagedType.LPWStr)] string app
);
[DllImport(FASTAIT_DLL)]
internal static extern int EndSession();
[DllImport(FASTAIT_DLL)]
internal static extern int OpenEngine(int key);
[DllImport(FASTAIT_DLL)]
internal static extern int CloseEngineM(int key);
[DllImport(FASTAIT_DLL)]
internal static extern int SimpleTransSentM(
int key,
[MarshalAs(UnmanagedType.LPWStr)] string fr,
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder t,
int unknown,
int unknown2
);
[DllImport(FASTAIT_DLL)]
internal static extern int SetBasicDictPathW(
int key,
[MarshalAs(UnmanagedType.LPWStr)] string fr
);
[DllImport(FASTAIT_DLL)]
internal static extern int SetProfDictPathW(
int key,
[MarshalAs(UnmanagedType.LPWStr)] string path,
int priority
);
一个使用例子:
static void Main(string[] args)
{
IntPtr buffer = Marshal.AllocHGlobal(buffersize);
try
{
string dicPath = PATH + DEFAULT_DIC;
StartSession(dicPath, buffer, buffer + buffersize, "DCT");//return 0 成功
OpenEngine(key); //return 0 成功
SetBasicDictPathW(key, dicPath);//return 0 成功
StringBuilder to = new StringBuilder(0x400);
SimpleTransSentM(key, "憎しみは憎しみしか生まない。", to, 0x28, 0x4);//return 0 成功
Console.WriteLine(to.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
CloseEngineM(key);
EndSession();
Marshal.FreeHGlobal(buffer);
}
}
结果如下:

Comments | 1 条评论
哥们,能把这个源码发一份给我吗? 急需啊,实在是找不到这个DLL,网上也没有其他的案例呀,C#调用离线翻译