[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 38# 小白龙

    SciLexer.dll应该是EasyScintilla.dll调用ScintillaNET.dll时,由ScintillaNET.dll生成的吧
    报错问题搞不懂
    vs的生成设置里可以设置32或64吧
    自带编译器看所在目录:Framework64下的csc是64位,Framework下的csc是32位

TOP

回复 40# 小白龙

啊,原来搞错了,自带C#编译器csc跟C,C++编译器cl不一样,不管32位还是64位的csc默认编译生成都是AnyCpu(AnyCpu是根据运行系统或调用程序自动适用32位或64位,简单来讲就是二合一)
EasyScintilla.dll 跟 ScintillaNET.dll 也都是AnyCpu (dotnetSDK里的工具CorFlags.exe可以查看,VS有带此工具)

因此出错猜测可能是为了检查类型或Debug附加把SciLexer.dll当成dotnet的dll来解释了(试试换成release)
也有可能为了安全或独立不加载临时目录里的dll(试试直接复制到项目对应的目录里)

TOP

回复 42# 小白龙

终于搞懂大部分细节啦,有兴趣就按下面的试试看吧

将最下面代码复制粘贴并保存,并将ScintillaNET.dll , EasyScintilla.dll跟代码文件放在同一文件夹(只有这3个文件),
然后打开cmd,定位到当前目录,用自带编译器编译成dll (thecom为代码文件 , csc路径改成自己的)
  1. csc /r:ScintillaNET.dll /r:EasyScintilla.dll  /target:library thecom
复制代码
接着用sn.exe生成强名key文件,thekey.snk是key文件名
(sn.exe路径改成自己的,sn.exe是dotnetSDK的工具,vs自带)
  1. sn.exe -k thekey.snk
复制代码
然后用ildasm.exe反编译之前生成的dll,thecom.dll是之前生成的dll名字, thecom.il是输出的il文件名
(ildasm.exe路径改成自己的,ildasm.exe是dotnetSDK的工具,vs自带)
  1. ildasm.exe thecom.dll /OUT:thecom.il
复制代码
删掉之前生成的dll

接着用自带的 il 编译器将 il 文件和 res 文件和 key 文件一起重新编译成 dll 文件
(ilasm路径改成自己的,系统自带)
  1. ilasm thecom.il /DLL /OUTPUT=thecom.dll /KEY=thekey.snk /RESOURCE=thecom.res
复制代码
最后注册 dll (需要管理员权限)
(regasm系统自带 , gacutil.exe是dotnetSDK的工具,vs自带,路径都改成自己的)
  1. regasm thecom.dll
  2. gacutil.exe /i thecom.dll
复制代码
完了之后就测试实际代码能不能用吧(估计不行)
ProgId是ExampleProject.Application
ps 中的话是 new-object -comobject ExampleProject.Application

cs代码:
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using EasyScintilla.Stylers;
  12. using EasyScintilla;
  13. using System.IO;
  14. using System.Reflection;
  15. using System.Runtime.InteropServices;
  16. namespace ExampleProject
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         public EasyScintilla.SimpleEditor editor;//编辑器声明
  21.         public System.Windows.Forms.Button theButton;//按钮声明
  22.         public String thertStr; //返回字符串声明
  23.          ///<summary>
  24.         /// Required designer variable.
  25.         /// </summary>
  26.         private System.ComponentModel.IContainer components = null;
  27.         /// <summary>
  28.         /// Clean up any resources being used.
  29.         ///重定义Form1释放函数
  30.         /// </summary>
  31.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  32.         protected override void Dispose(bool disposing)
  33.         {
  34.             if (disposing && (components != null))
  35.             {
  36.                 components.Dispose();
  37.             }
  38.             base.Dispose(disposing);
  39.         }
  40.         //定义Form1关闭事件函数,用于关闭时储存编辑器文本
  41.         private void Form1_Closing(object sender, EventArgs e){thertStr=editor.Text;}
  42.         //Form1构造函数
  43.         public Form1()
  44.         {
  45.             InitializeComponent();//调用初始化函数
  46.         }
  47.         #region Windows Form Designer generated code
  48.         /// <summary>
  49.         /// Required method for Designer support - do not modify
  50.         /// the contents of this method with the code editor.
  51.         ///初始化函数定义
  52.         /// </summary>
  53.         private void InitializeComponent()
  54.         {
  55.             this.editor = new EasyScintilla.SimpleEditor();//创建编辑器
  56.             this.theButton = new System.Windows.Forms.Button();//创建按钮
  57.             this.SuspendLayout();
  58.             //
  59.             // editor设置
  60.             //
  61.             this.editor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  62.             | System.Windows.Forms.AnchorStyles.Left)
  63.             | System.Windows.Forms.AnchorStyles.Right)));
  64.             this.editor.IndentationGuides = ScintillaNET.IndentView.LookBoth;
  65.             this.editor.Location = new System.Drawing.Point(12, 12);
  66.             this.editor.Name = "editor";
  67.             this.editor.Size = new System.Drawing.Size(854, 603);
  68.             this.editor.Styler = null;
  69.             this.editor.TabIndex = 0;
  70.             //
  71.             // 按钮设置
  72.             //
  73.             this.theButton.Size=new System.Drawing.Size(100, 21);
  74.             this.theButton.Location=new System.Drawing.Point(12, 621);
  75.             this.theButton.Name="button1";
  76.             this.theButton.Text="OK";
  77.             //
  78.             // Form1设置
  79.             //
  80.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  81.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  82.             this.ClientSize = new System.Drawing.Size(878, 656);
  83.             this.Controls.Add(this.theButton);//添加按钮到Form1
  84.             this.Controls.Add(this.editor);//添加编辑器到Form1
  85.             this.Name = "Form1";
  86.             this.Text = "EasyScintilla Test App";
  87.             //this.Load += new System.EventHandler(this.Form1_Load);
  88.             this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);//添加关闭事件
  89.             this.ResumeLayout(false);
  90.         }
  91.         #endregion
  92.     }
  93. //========================================
  94. //========================================
  95. /*
  96. [ComVisible(true)]
  97. [Guid("E2032C8D-2E32-4415-8E8C-CFACBCAAADFF")]
  98. public interface TheCom{
  99. [DispId(1)]
  100. string EasySci (string code, string codeType);
  101. }
  102. */
  103. [ComVisible(true)]
  104. [Guid("BF4EFCF8-8F67-46F2-A84F-E88C8C3DD777"),
  105. ClassInterface(ClassInterfaceType.None)]//,
  106. //ComSourceInterfaces(typeof(TheCom))]
  107. [ProgId("ExampleProject.Application")]
  108. public class Nakano{// : TheCom{
  109. public string EasySci (string code, string codeType)
  110. {
  111. Hashtable theStyler=new Hashtable();
  112. theStyler.Add("C#", new CSharpStyler());
  113. theStyler.Add("C# (Dark)", new DarkCSharpStyler());
  114. theStyler.Add("Windows Batch" ,new BatchStyler());
  115. theStyler.Add("HTML",  new HtmlStyler());
  116. theStyler.Add("JSON",  new JsonStyler());
  117. theStyler.Add("PowerShell",  new PowerShellStyler());
  118. theStyler.Add("Python", new PythonStyler());
  119. theStyler.Add("Ruby", new RubyStyler());
  120. theStyler.Add("T-SQL", new SqlStyler());
  121. theStyler.Add("Teradata Parallel Transporter", new TptStyler());
  122. var theForm1=new Form1();
  123. StringBuilder theStr;
  124. if(theStyler.ContainsKey(codeType))
  125. {
  126. theForm1.editor.Styler=(ScintillaStyler)theStyler[codeType];
  127. }
  128. theForm1.editor.Text=code;
  129. theForm1.ShowDialog();
  130. theStr=new StringBuilder(theForm1.thertStr);
  131. theForm1.Dispose();
  132. return theStr.ToString();
  133. }
  134. }
  135. //========================================
  136. //========================================
  137. }
复制代码

TOP

返回列表