{"id":99468,"date":"2020-04-13T09:24:11","date_gmt":"2020-04-13T01:24:11","guid":{"rendered":"http:\/\/4563.org\/?p=99468"},"modified":"2020-04-13T09:24:11","modified_gmt":"2020-04-13T01:24:11","slug":"c-%e5%8a%a8%e6%80%81%e8%b0%83%e7%94%a8%e5%ba%93%e9%97%ae%e9%a2%98%ef%bc%8c-node-js-%e8%b0%83%e7%94%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=99468","title":{"rendered":"C++ \u52a8\u6001\u8c03\u7528\u5e93\u95ee\u9898\uff0c node.js \u8c03\u7528"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  C++ \u52a8\u6001\u8c03\u7528\u5e93\u95ee\u9898\uff0c node.js \u8c03\u7528               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hua123s <\/span>  <span><i><\/i> 61<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u73b0\u5728\u6709\u4e00\u4e2a dll \u52a0\u5934\u6587\u4ef6\uff0c\u597d\u50cf\u662f\u51fd\u6570\u6ca1\u6709 export \u6211\u6709\u4ec0\u4e48\u529e\u6cd5\u53bb\u5728\u4e0d\u719f\u6089 C++\u8bed\u6cd5\u7684\u60c5\u51b5\u4e0b\uff0c\u8ba9 node.js \u53ef\u4ee5\u8c03\u7528\u8fd9\u4e2a dll \uff1f<\/p>\n<p>\u65b9\u6cd5 1.\u7a0d\u5fae\u5b66\u4e60 C++ \u65b9\u6cd5 2. \u8bf7\u6559\u5404\u4f4d\u5927\u4f6c\uff0c\u6709\u4ec0\u4e48 tips \uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"742417\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sc3263 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             0. \u627e\u4e2a\u5199\u8fc7 C\/C++\u7684\u540c\u4e8b \/\u670b\u53cb\u534f\u52a9\u4f60<br \/>1. \u786e\u5b9a\u52a8\u6001\u5e93\u662f x86 \u8fd8\u662f x64 \u7684\u3002\u540e\u7eed\u8c03\u7528\u7684 node.js \u8fd0\u884c\u65f6\u9700\u8981\u548c\u5b83\u4e00\u6837<br \/>2. \u5bf9\u7740 node-addon-api \u7684\u4f8b\u5b50\u6539\u4e00\u4e0b\u3002<br \/>https:\/\/github.com\/nodejs\/node-addon-examples\/tree\/master\/1_hello_world\/node-addon-api<br \/>binding.gyp \u91cc\u52a0\u8981\u94fe\u63a5\u7684\u52a8\u6001\u5e93\u3002<br \/>hello.cc \u91cc\u52a0\u5bf9\u5e94\u7684\u8c03\u7528\u3002\u57fa\u672c\u4e0a\u5c31\u662f\u589e\u52a0 Napi::Value MethodName(const Napi::CallbackInfo&amp; info)\u7684\u51fd\u6570\uff0c\u628a info \u4e2d\u7684\u5165\u53c2\u89e3\u6790\u51fa\u6765\uff0c\u8c03\u7528\u5bf9\u5e94\u7684 C++\u51fd\u6570\uff0c\u62ff\u5230\u8fd4\u56de\u503c\uff0c\u518d\u5305\u6210 Napi::Value \u8fd4\u56de\u3002\u6700\u540e\u5728 Napi::Object Init(Napi::Env env, Napi::Object exports)\u91cc\u628a\u5199\u597d\u7684\u51fd\u6570 set \u5230 exports\u3002<br \/>js \u4e2d\u7684\u7528\u6cd5\u53c2\u7167 hello.js<br \/>3. \u65e0\u5c3d\u7684\u67e5 node addon api \u6587\u6863+debug<br \/>4. \u7948\u7977\u4f60\u7684\u52a8\u6001\u5e93\u8c03\u7528\u91cc\u6ca1\u6709\u5565\u9700\u8981\u6ce8\u518c\u56de\u8c03\u7684\u3002\u4e0d\u7136\u53c8\u662f\u53e6\u5916\u4e00\u573a\u5669\u68a6\u3002<br \/>\u8fd9\u6837\u5e94\u8be5\u53ef\u4ee5\u51fa\u4e2a\u51d1\u5408\u80fd\u7528\u7684\u7248\u672c\u3002\u6240\u6709\u5bf9\u52a8\u6001\u5e93\u65b9\u6cd5\u7684\u8c03\u7528\u90fd\u662f\u5728\u4e3b\u7ebf\u7a0b\u4e2d\u5b8c\u6210\u7684\u3002\u8981\u662f\u52a8\u6001\u5e93\u65b9\u6cd5\u4f1a\u6267\u884c\u5f88\u957f\u65f6\u95f4\u7684\u8bdd\uff0c\u4f1a\u963b\u585e\u4e3b\u7ebf\u7a0b\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742418\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : hua123s <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sc3263 \u8c22\u8c22\u5927\u4f6c,                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742419\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : hua123s <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sc3263 \u5927\u4f6c \u53ef\u4ee5\u8be2\u95ee\u4e0b \u60a8\u4e00\u822c\u4e00\u4e2a C++\u5bf9\u8c61\u600e\u4e48\u8f6c\u6362\u6210 javascript object \u7684\uff1f<br \/>\u6bcf\u4e2a\u5c5e\u6027\u4e00\u5bf9\u5e94\u5199\u6620\u5c04\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"742420\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sc3263 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @hua123s \u53ef\u4ee5\u6309\u7167<br \/>https:\/\/github.com\/nodejs\/node-addon-api\/blob\/master\/doc\/object_wrap.md<br \/>\u91cc\u63d0\u5230\u7684\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7ee7\u627f\u81ea Napi::ObjectWrap \u7684\u5305\u88c5\u7c7b\uff0c\u5728\u91cc\u9762\u5b9e\u73b0 C++\u7684\u4ee3\u7801\u3002<br \/>\u6211\u662f\u76f4\u63a5\u5728\u5305\u88c5\u7c7b\u5bf9\u8c61\u91cc\u5b58 C++\u5bf9\u8c61\u7684\u6307\u9488\u3002\u6784\u9020\u65f6\u65b0\u5efa C++\u5bf9\u8c61\uff0c\u6790\u6784\u65f6\u5220\u9664\uff0c\u518d\u6dfb\u52a0\u9700\u8981\u66b4\u9732\u7ed9 JS \u7684\u6210\u5458\u51fd\u6570\uff0c\u5728\u91cc\u9762\u8c03\u7528 C++\u7684\u5bf9\u8c61\u5bf9\u5e94\u7684\u65b9\u6cd5\u3002<br \/>hmmmmmmmm<br \/>\u57fa\u672c\u4e0a\u5c31\u662f\u4f60\u8bf4\u7684\uff0c\u5c5e\u6027\u4e00\u4e00\u5bf9\u5e94\u5199\u6620\u5c04\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>C++ \u52a8\u6001\u8c03\u7528\u5e93\u95ee\u9898\uff0c node&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/99468"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99468"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/99468\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99468"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}