回复 42# 小白龙
终于搞懂大部分细节啦,有兴趣就按下面的试试看吧
将最下面代码复制粘贴并保存,并将ScintillaNET.dll , EasyScintilla.dll跟代码文件放在同一文件夹(只有这3个文件),
然后打开cmd,定位到当前目录,用自带编译器编译成dll (thecom为代码文件 , csc路径改成自己的)- csc /r:ScintillaNET.dll /r:EasyScintilla.dll /target:library thecom
复制代码 接着用sn.exe生成强名key文件,thekey.snk是key文件名
(sn.exe路径改成自己的,sn.exe是dotnetSDK的工具,vs自带)复制代码 然后用ildasm.exe反编译之前生成的dll,thecom.dll是之前生成的dll名字, thecom.il是输出的il文件名
(ildasm.exe路径改成自己的,ildasm.exe是dotnetSDK的工具,vs自带)- ildasm.exe thecom.dll /OUT:thecom.il
复制代码 删掉之前生成的dll
接着用自带的 il 编译器将 il 文件和 res 文件和 key 文件一起重新编译成 dll 文件
(ilasm路径改成自己的,系统自带)- ilasm thecom.il /DLL /OUTPUT=thecom.dll /KEY=thekey.snk /RESOURCE=thecom.res
复制代码 最后注册 dll (需要管理员权限)
(regasm系统自带 , gacutil.exe是dotnetSDK的工具,vs自带,路径都改成自己的)- regasm thecom.dll
- gacutil.exe /i thecom.dll
复制代码 完了之后就测试实际代码能不能用吧(估计不行)
ProgId是ExampleProject.Application
ps 中的话是 new-object -comobject ExampleProject.Application
cs代码:- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using EasyScintilla.Stylers;
- using EasyScintilla;
-
- using System.IO;
- using System.Reflection;
- using System.Runtime.InteropServices;
-
- namespace ExampleProject
- {
- public partial class Form1 : Form
- {
-
- public EasyScintilla.SimpleEditor editor;//编辑器声明
- public System.Windows.Forms.Button theButton;//按钮声明
- public String thertStr; //返回字符串声明
-
- ///<summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
-
- /// <summary>
- /// Clean up any resources being used.
- ///重定义Form1释放函数
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- //定义Form1关闭事件函数,用于关闭时储存编辑器文本
- private void Form1_Closing(object sender, EventArgs e){thertStr=editor.Text;}
-
- //Form1构造函数
- public Form1()
- {
- InitializeComponent();//调用初始化函数
- }
-
- #region Windows Form Designer generated code
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///初始化函数定义
- /// </summary>
- private void InitializeComponent()
- {
- this.editor = new EasyScintilla.SimpleEditor();//创建编辑器
- this.theButton = new System.Windows.Forms.Button();//创建按钮
- this.SuspendLayout();
-
- //
- // editor设置
- //
- this.editor.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.editor.IndentationGuides = ScintillaNET.IndentView.LookBoth;
- this.editor.Location = new System.Drawing.Point(12, 12);
- this.editor.Name = "editor";
- this.editor.Size = new System.Drawing.Size(854, 603);
- this.editor.Styler = null;
- this.editor.TabIndex = 0;
-
- //
- // 按钮设置
- //
- this.theButton.Size=new System.Drawing.Size(100, 21);
- this.theButton.Location=new System.Drawing.Point(12, 621);
- this.theButton.Name="button1";
- this.theButton.Text="OK";
-
- //
- // Form1设置
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(878, 656);
- this.Controls.Add(this.theButton);//添加按钮到Form1
- this.Controls.Add(this.editor);//添加编辑器到Form1
- this.Name = "Form1";
- this.Text = "EasyScintilla Test App";
- //this.Load += new System.EventHandler(this.Form1_Load);
- this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);//添加关闭事件
- this.ResumeLayout(false);
- }
- #endregion
- }
-
- //========================================
- //========================================
- /*
- [ComVisible(true)]
- [Guid("E2032C8D-2E32-4415-8E8C-CFACBCAAADFF")]
- public interface TheCom{
- [DispId(1)]
- string EasySci (string code, string codeType);
- }
- */
-
- [ComVisible(true)]
- [Guid("BF4EFCF8-8F67-46F2-A84F-E88C8C3DD777"),
- ClassInterface(ClassInterfaceType.None)]//,
- //ComSourceInterfaces(typeof(TheCom))]
- [ProgId("ExampleProject.Application")]
-
- public class Nakano{// : TheCom{
-
- public string EasySci (string code, string codeType)
- {
- Hashtable theStyler=new Hashtable();
- theStyler.Add("C#", new CSharpStyler());
- theStyler.Add("C# (Dark)", new DarkCSharpStyler());
- theStyler.Add("Windows Batch" ,new BatchStyler());
- theStyler.Add("HTML", new HtmlStyler());
- theStyler.Add("JSON", new JsonStyler());
- theStyler.Add("PowerShell", new PowerShellStyler());
- theStyler.Add("Python", new PythonStyler());
- theStyler.Add("Ruby", new RubyStyler());
- theStyler.Add("T-SQL", new SqlStyler());
- theStyler.Add("Teradata Parallel Transporter", new TptStyler());
- var theForm1=new Form1();
- StringBuilder theStr;
- if(theStyler.ContainsKey(codeType))
- {
- theForm1.editor.Styler=(ScintillaStyler)theStyler[codeType];
- }
- theForm1.editor.Text=code;
- theForm1.ShowDialog();
- theStr=new StringBuilder(theForm1.thertStr);
- theForm1.Dispose();
- return theStr.ToString();
- }
- }
- //========================================
- //========================================
- }
复制代码
|