在中望CAD中设置环境变量
Acad做法
在AutoCAD中,我们一般采用PInvoke的方式设置环境变量,因为官方没有给.net提供设置环境变量的API
[DllImport("accore.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.Cdecl,EntryPoint = "acedSetEnv")]
private static extern int AcedSetEnv(string? envName, StringBuilder newValue);
中望CAD做法
通过导出PE入口点可以发现,中望的入口和Acad是差不多的,但是直接改EntryPoint调用发现无法生效
解决方案是,手动指定CharSet = CharSet.Unicode
[DllImport("zwcad.exe", CharSet = CharSet.Unicode,
CallingConvention = CallingConvention.Cdecl, EntryPoint = "zcedSetEnv")]
private static extern int AcedSetEnv(string? envName, StringBuilder newValue);
完
评论