{"id":1160,"date":"2010-06-26T15:04:00","date_gmt":"2010-06-26T07:04:00","guid":{"rendered":""},"modified":"2013-11-17T16:44:13","modified_gmt":"2013-11-17T08:44:13","slug":"dll%e5%b0%81%e8%a3%85%e7%aa%97%e4%bd%93%e6%96%b9%e6%b3%95%e5%b9%b6%e5%ae%9e%e7%8e%b0c%e8%b0%83%e7%94%a8","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1160.html","title":{"rendered":"DLL\u5c01\u88c5\u7a97\u4f53\u65b9\u6cd5\u5e76\u5b9e\u73b0C#\u8c03\u7528"},"content":{"rendered":"<p>\u7528DELPHI\u521b\u5efaDLL\u6587\u4ef6\uff0c\u5c01\u88c5\u7a97\u4f53\u7684\u5b9e\u73b0\u65b9\u6cd5\u5b9e\u4f8b\uff1a<br \/>\n\u5373\u4e00\u4e2a\u7a0b\u5e8f\u4e0d\u518d\u662f\u5355\u4e00\u7684\u4e00\u4e2aEXE\u6587\u4ef6\u4e86\uff0c\u800c\u662f\u7531\u4e00\u4e2aEXE\u6587\u4ef6\u52a0N\u4e2aDLL\u6587\u4ef6\u7ec4\u6210\uff0c\u8fd9\u6837\u505a\u7684\u539f\u56e0\u662f\u65b9\u4fbf\u4ee5\u540e\u7684\u7ef4\u62a4\u4e0e\u66f4\u65b0\uff0c\u4e5f\u662f\u8de8\u5e73\u53f0\u5f00\u53d1\u7684\u91cd\u8981\u4e00\u6b65\u3002<br \/>\n1\uff0c \u6253\u5f00DELPHI\uff0c\u65b0\u5efa\u4e00\u4e2aDll Wizard<br \/>\n2\uff0c \u5728\u65b0\u5efa\u7684Dll\u91cc\u65b0\u5efa\u4e00\u4e2aForm<br \/>\n3\uff0c \u5728\u65b0\u5efa\u7684Form\u91ccuses stdctrls<br \/>\n4\uff0c \u5728var\u4e0b\u9762\u5199\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nProcedure SynAPP(App:THandle);stdcall;\r\nProcedure ShowForm;stdcall;\r\n<\/pre>\n<p>(\u6ce8\uff1a\u5982\u679c\u8981\u8ba9C#\u8c03\u7528\uff0c\u5219\u5e94\u8be5\u6ce8\u610f\u51fd\u6570\u7684\u5927\u5c0f\u5199\u3002)<\/p>\n<p>6\uff0c<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nvar\r\n  Form1: TForm1;\r\n  Procedure SynAPP(App:THandle);stdcall;\r\n  Procedure ShowForm;stdcall;\r\n\r\nimplementation\r\n\r\n{$R *.dfm}\r\nProcedure SynAPP(App:THandle);stdcall;\r\nBegin\r\n  Application.Handle:=app;\r\nEnd;\r\n\r\nProcedure ShowForm;stdcall;\r\nBegin\r\n  Form1 := Tform1.create(Application);\r\n  Form1.ShowModal;\r\n  FreeAndNil(Form1);\r\nEnd;\r\n<\/pre>\n<p>\u4e00\u5b9a\u8981\u6ce8\u610fFreeAndNil(Form1);\u4e00\u5b9a\u8981\u6709\u3002<\/p>\n<p>7\uff0c \u5728dll\u7684Library\u6587\u4ef6\u91cc\u7684{$R *.res}\u4e0b\u9762\u5199\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nexports\r\nSynAPP,ShowForm;\r\n<\/pre>\n<p>\u4e0a\u9762\u5230\u6b64\u4e3a\u6b62\u5b8c\u6210\u4e86DLL\u5c01\u88c5\u7a97\u4f53\u7684\u521b\u5efa<br \/>\n\u4e0b\u9762\u662f\u8c03\u7528\u4e86<br \/>\n1\uff0c \u5728\u8981\u8c03\u7528DLL\u6587\u4ef6\u7684\u7a0b\u5e8f\u7684var\u4e0b\u5199\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nProcedure SynAPP(App:THandle);stdcall;external 'my.dll' ;\/\/----\u4f60\u7684DLL\u6587\u4ef6\u540d\r\nProcedure ShowForm;stdcall;external 'my.dll';\/\/----\u4f60\u7684DLL\u6587\u4ef6\u540d\r\n<\/pre>\n<p>\u6ce8\uff1a\u628a\u4f60\u5199\u597d\u7684DLL\u653e\u5728\u672c\u7a0b\u5e8f\u7684\u540c\u4e00\u76ee\u5f55\u4e0b;<br \/>\n2\uff0c \u5728\u4f60\u7684\u7a0b\u5e8f\u7684Button\u7684On Click\u4e8b\u4ef6\u4e0b\u5199\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nSynAPP(applicatiln.Handle);\r\nShowForm;\r\n<\/pre>\n<p>\u5728C#\u4e2d\u8c03\u7528\u5c31\u8fd9\u6837\u5199\uff1a<br \/>\n\u5148\u52a0\u5165\u5f15\u7528\uff1ausing System.Runtime.InteropServices;<br \/>\n\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing System.Drawing;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Windows.Forms;\r\nusing System.Runtime.InteropServices;\r\n\r\nnamespace dllForm\r\n{\r\n    public partial class Form1 : Form\r\n    {\r\n        public Form1()\r\n        {\r\n            InitializeComponent();\r\n        }\r\n        private const string _fileDll = @&quot;C:\\Users\\chenming\\Desktop\\dllForm\\dllForm\\bin\\Debug\\dllForm.dll&quot;;\r\n        &#x5B;DllImport(_fileDll, EntryPoint = &quot;SynAPP&quot;, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]\r\n        public static extern string SynAPP(IntPtr i);\r\n        &#x5B;DllImport(_fileDll, EntryPoint = &quot;ShowForm&quot;, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]\r\n        public static extern string ShowForm();\r\n\r\n        private void button1_Click(object sender, EventArgs e)\r\n        {\r\n            SynAPP(this.Handle);\r\n            ShowForm();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>\u5176\u5b83\u6ce8\u610f\u7684\u5730\u65b9\uff1a<br \/>\n1.C#\u4e2d\u7684double\u4e0eDelphi\u4e2d\u7684double\u6570\u636e\u7c7b\u578b\u5bf9\u5e94\u3002\u4e0d\u80fd\u662fDelphi\u4e2d\u7684Extended\u7c7b\u578b\u3002<br \/>\n2.Delphi\u4e2d\u7684\u51fd\u6570\u7684\u8fd4\u56de\u4e0d\u80fd\u4e3aStirng\uff0c\u6539\u4e3aPChar\uff0c\u53c2\u6570\u53ef\u4ee5\u4e3aString\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528DELPHI\u521b\u5efaDLL\u6587\u4ef6\uff0c\u5c01\u88c5\u7a97\u4f53\u7684\u5b9e\u73b0\u65b9\u6cd5\u5b9e\u4f8b\uff1a \u5373\u4e00\u4e2a\u7a0b\u5e8f\u4e0d\u518d\u662f\u5355\u4e00\u7684\u4e00\u4e2aEXE\u6587\u4ef6\u4e86\uff0c\u800c\u662f\u7531\u4e00\u4e2aEX [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1160","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"predecessor-version":[{"id":4698,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions\/4698"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}