{"id":3297,"date":"2024-11-10T14:00:08","date_gmt":"2024-11-10T06:00:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3297\/"},"modified":"2024-11-10T14:00:08","modified_gmt":"2024-11-10T06:00:08","slug":"js%e5%a6%82%e4%bd%95%e8%bd%acdllq","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3297\/","title":{"rendered":"js\u5982\u4f55\u8f6cdllq"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5c06 javascript \u8f6c\u6362\u4e3a dll\uff1f\u6b65\u9aa4\uff1a\u4f7f\u7528 node.js\uff0c\u521b\u5efa\u4e00\u4e2a javascript \u6587\u4ef6\u5e76\u4f7f\u7528 node-gyp \u6a21\u5757\u521b\u5efa dll \u6587\u4ef6\u3002\u5728 c# \u6216\u5176\u4ed6 .net \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528dllimport\u51fd\u6570\u52a0\u8f7d\u548c\u8c03\u7528 dll\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110809183428998.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u8f6cdllq\u63d2\u56fe\" alt=\"js\u5982\u4f55\u8f6cdllq\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 JavaScript \u8f6c\u6362\u4e3a DLL\uff1f<\/strong><\/p>\n<p>JavaScript \u662f\u4e00\u79cd\u811a\u672c\u8bed\u8a00\uff0c\u901a\u5e38\u5728\u7f51\u7edc\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\u3002\u53e6\u4e00\u65b9\u9762\uff0cDLL\uff08\u52a8\u6001\u94fe\u63a5\u5e93\uff09\u662f\u4e00\u79cd\u5728 Windows \u4e2d\u52a0\u8f7d\u7684\u53ef\u6267\u884c\u4ee3\u7801\u3002\u5c06 JavaScript \u8f6c\u6362\u4e3a DLL \u53ef\u4ee5\u4f7f\u60a8\u5728\u4f20\u7edf\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 JavaScript \u4ee3\u7801\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u4f7f\u7528 Node.js\uff1a<\/strong> Node.js \u662f\u4e00\u79cd\u670d\u52a1\u5668\u7aef JavaScript \u73af\u5883\uff0c\u5141\u8bb8\u60a8\u5728\u547d\u4ee4\u884c\u6216 Windows \u670d\u52a1\u7b49\u975e\u6d4f\u89c8\u5668\u73af\u5883\u4e2d\u8fd0\u884c JavaScript \u4ee3\u7801\u3002<\/li>\n<li> <strong>\u521b\u5efa JavaScript \u6587\u4ef6\uff1a<\/strong>\u7f16\u5199\u60a8\u8981\u8f6c\u6362\u4e3a DLL \u7684 JavaScript \u4ee3\u7801\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a .js \u6587\u4ef6\u3002<\/li>\n<li> <strong>\u521b\u5efa DLL \u6587\u4ef6\uff1a<\/strong>\u4f7f\u7528 Node-gyp \u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u521b\u5efa DLL \u6587\u4ef6\uff1a<\/li>\n<\/ol>\n<pre>npm install node-gyp\nnode-gyp configure\nnode-gyp build<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li> <strong>\u8c03\u7528 DLL\uff1a<\/strong>\u5728 C# \u6216\u5176\u4ed6 .NET \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 System.Runtime.InteropServices \u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u51fd\u6570\u52a0\u8f7d\u548c\u8c03\u7528 DLL\u3002<\/li>\n<\/ol>\n<pre>[DllImport(\"my_dll.dll\")]\npublic static extern int JS_Function(int a, int b);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5c06 JavaScript \u4ee3\u7801\u8f6c\u6362\u4e3a DLL \u7684\u793a\u4f8b\uff1a<\/p>\n<p><strong>my_dll.js:<\/strong><\/p>\n<pre>function JS_Function(a, b) {\n  return a + b;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Node-gyp \u521b\u5efa DLL:<\/strong><\/p>\n<pre>npm install node-gyp\ncd my_dll\nnode-gyp configure\nnode-gyp build<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u5728 .NET \u5e94\u7528\u7a0b\u5e8f\u4e2d\u52a0\u8f7d\u548c\u8c03\u7528 DLL\uff1a<\/p>\n<pre>\/\/ \u52a0\u8f7d DLL\n[DllImport(\"my_dll.dll\")]\npublic static extern int JS_Function(int a, int b);\n\n\/\/ \u8c03\u7528 DLL \u51fd\u6570\nint result = JS_Function(10, 20);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u8f6cdllq\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5c06 javascript \u8f6c\u6362\u4e3a dll\uff1f\u6b65\u9aa4\uff1a\u4f7f\u7528 node.js\uff0c\u521b\u5efa\u4e00\u4e2a javascript \u6587\u4ef6\u5e76\u4f7f\u7528 node-gyp \u6a21\u5757\u521b\u5efa dll \u6587\u4ef6\u3002\u5728 c# \u6216\u5176\u4ed6 .net \u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528dllimport\u51fd\u6570\u52a0\u8f7d\u548c\u8c03\u7528 dll\u3002 \u5982\u4f55\u5c06 JavaScript \u8f6c\u6362\u4e3a DLL\uff1f JavaScript \u662f\u4e00\u79cd\u811a\u672c\u8bed\u8a00\uff0c\u901a\u5e38\u5728\u7f51\u7edc\u6d4f\u89c8\u5668\u4e2d\u6267\u884c\u3002\u53e6\u4e00\u65b9\u9762\uff0cDLL\uff08\u52a8\u6001\u94fe\u63a5\u5e93\uff09\u662f\u4e00\u79cd\u5728 Windows \u4e2d\u52a0\u8f7d\u7684\u53ef\u6267\u884c\u4ee3\u7801\u3002\u5c06 JavaScript \u8f6c\u6362\u4e3a DLL \u53ef\u4ee5\u4f7f\u60a8\u5728\u4f20\u7edf\u7684\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u4e2d\u4f7f\u7528 JavaScript \u4ee3\u7801\u3002 \u6b65\u9aa4\uff1a \u4f7f\u7528 Node.js\uff1a Node.js \u662f\u4e00\u79cd\u670d\u52a1\u5668\u7aef JavaScript \u73af\u5883\uff0c\u5141\u8bb8\u60a8\u5728\u547d\u4ee4\u884c\u6216 Windows \u670d\u52a1\u7b49\u975e\u6d4f\u89c8\u5668\u73af\u5883\u4e2d\u8fd0\u884c JavaScript \u4ee3\u7801\u3002 \u521b\u5efa JavaScript \u6587\u4ef6\uff1a\u7f16\u5199\u60a8\u8981\u8f6c\u6362\u4e3a DLL \u7684 JavaScript \u4ee3\u7801\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a .js \u6587\u4ef6\u3002 \u521b\u5efa DLL \u6587\u4ef6\uff1a\u4f7f\u7528 Node-gyp \u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u521b\u5efa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3297","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3297"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3297\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}