{"id":1389,"date":"2023-07-26T22:21:02","date_gmt":"2023-07-26T14:21:02","guid":{"rendered":"https:\/\/lyvba.com\/?p=1389"},"modified":"2023-07-27T08:06:03","modified_gmt":"2023-07-27T00:06:03","slug":"zerobase-learn-cpp-02","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/07\/26\/zerobase-learn-cpp-02\/","title":{"rendered":"\u539f\u521b:\u6298\u817e\u4e86\u4e24\u4e2a\u665a\u4e0a-VBA\u8c03\u7528C++\u7684dll\u505a\u4e2d\u82f1\u6587\u7684\u8bed\u8a00\u5305\u6280\u672f\u96be\u5173\u653b\u514b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/07\/i18n.webp\" alt=\"\" \/><\/p>\n<h2>VBA\u4f7f\u7528\u7528\u6cd5  CorelDRAW X6 62bit<\/h2>\n<pre><code class=\"language-vb\">&#039;\/\/ For CorelDRAW X6-2023  62bit\nPublic Declare PtrSafe Function i18n Lib &quot;C:\\TSP\\lyvba.dll&quot; (ByVal str As String, ByVal code As Long) As String\n\nSub Test_i18n()\n  MsgBox i18n(&quot;Nodes&quot;, 2052)\n  MsgBox i18n(&quot;Nodes&quot;, 1033)\n  MsgBox i18n(&quot;Preset Property&quot;, 2052)\nEnd Sub<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/07\/vba_i18n.webp\" alt=\"\" \/><\/p>\n<h3>C++ \u7f16\u8bd1 DLL \u7684\u6e90\u7801: \u6709\u5174\u8da3\u7684\u73a9\u7684\uff0c\u81ea\u5df1\u624b\u5de5\u6572\u5427\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u6709\u5f88\u591a\u5751\uff0c\u53ea\u6709\u81ea\u5df1\u4ece\u5751\u91cc\u722c\u51fa\u6765\u624d\u7b97\u771f\u638c\u63e1<\/h3>\n<h3>\u5f53\u7136\u4ee3\u7801\u5e94\u8be5\u8fd8\u6709BUG\uff0c\u4e0d\u8fc7\u80fd\u73a9\u5c31\u884c<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2023\/07\/i18n_cpp.png\" alt=\"\" \/><\/p>\n<h3>\u5728 VBA \u4e2d\u8c03\u7528 C++ DLL \u51fd\u6570\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u6570\u636e\u7c7b\u578b\u7684\u517c\u5bb9\u6027\u95ee\u9898\u3002\u7279\u522b\u662f\u5b57\u7b26\u4e32\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5728 C++ \u4e2d\u5b57\u7b26\u4e32\u901a\u5e38\u662f\u4f7f\u7528\u5b57\u7b26\u6570\u7ec4\u6216\u6307\u9488\u6765\u8868\u793a\u3002\u7f51\u4e0a\u641c\u4e86\u5f88\u591a\u65b9\u6cd5\uff0c\u4e5f\u95ee\u4e86GPT\uff0c\u597d\u50cf\u6ca1\u6709\u5b8c\u5168\u6b63\u786e\u7684\u63cf\u8ff0\u3002<\/h3>\n<h3>\u6bd4\u5982 GPT \u8bf4 <em>\u5728 VBA \u4e2d\uff0cString \u7c7b\u578b\u901a\u5e38\u88ab\u5b9e\u73b0\u4e3a Unicode \u5b57\u7b26\u4e32\uff0c\u5373\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528\u4e24\u4e2a\u5b57\u8282\u3002\u5982\u679c\u9700\u8981\u5c06 VBA \u4e2d\u7684 Unicode \u5b57\u7b26\u4e32\u4f20\u9012\u7ed9 C \u8bed\u8a00\u7684 DLL\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u683c\u5f0f\u5316\u548c\u7c7b\u578b\u8f6c\u6362\u64cd\u4f5c\uff0c\u4ee5\u4fbf\u4f7f C \u51fd\u6570\u80fd\u591f\u6b63\u786e\u5730\u63a5\u53d7\u548c\u5904\u7406\u5b57\u7b26\u4e32\u53c2\u6570\u3002<\/em><\/h3>\n<h3>\u4f46\u662f <code>CorelDRAW X6 VBA<\/code> \u5b9e\u9645 <code>String<\/code> \u662f\u672c\u5730\u5b57\u7b26\u96c6\u7684\u3002\u4f20\u5165\u5230C++\u4e2d\uff0c\u9700\u8981 BSTR\u662fMicrosoft\u5b9a\u4e49\u7684\u4e00\u79cd\u5b57\u7b26\u4e32\u6570\u636e\u7c7b\u578b \u8f6c\u63a5\uff0c\u800c\u53c8\u8981\u6309 \u7c7b\u4f3c char \u5355\u5b57\u8282\u5904\u7406\u3002<\/h3>\n<p>\u4ee3\u7801\u4e2d\u4f7f\u7528<code>(char*)<\/code>\u548c <code>string<\/code> \u76f4\u63a5\u628a <code>BSTR<\/code> \u8f6c\u6210\u4e86 C++ \u6570\u636e\u7ed3\u6784<\/p>\n<pre><code class=\"language-cpp\">BSTR english;\nstring key = string((char*)english);<\/code><\/pre>\n<p>DLL \u8fd4\u56de\u5b57\u7b26\u4e32 \u5230VBA\uff0c\u8fd8\u662f\u4f7f\u7528\u4e86\u5355\u5b57\u8282\u7684\u8f6c\u6362\u51fd\u6570 <code>CharToBSTR<\/code><\/p>\n<pre><code class=\"language-cpp\">BSTR CharToBSTR(const char* str)\n{\n    \/\/ \u83b7\u53d6char*\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff08\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\n    int len = strlen(str);\n\n    \/\/ \u5206\u914dBSTR\u5b57\u7b26\u4e32\u7684\u5185\u5b58\uff08\u6309\u5b57\u8282\u5206\u914d\uff09\n    BSTR bstr = SysAllocStringByteLen(nullptr, len);\n\n    \/\/ \u5c06char*\u5b57\u7b26\u4e32\u7684\u5185\u5bb9\u9010\u5b57\u8282\u590d\u5236\u5230BSTR\u5b57\u7b26\u4e32\u4e2d\n    memcpy(bstr, str, len);\n\n    return bstr;\n}<\/code><\/pre>\n<h3>\u73b0\u5728\u63a5\u53e3\u867d\u7136\u5199\u597d\u4e86\uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u6709BUG\uff0c\u53ea\u6709\u6d4b\u8bd5\u770b\u770b\uff0c\u6162\u6162\u6539\u6210\u6210\u719f\u63a5\u53e3\u3002<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>VBA\u4f7f\u7528\u7528\u6cd5 CorelDRAW X6 62bit &#039;\/\/ For CorelDRAW  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1380,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[31,67],"class_list":["post-1389","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","tag-cpp","tag-vba"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=1389"}],"version-history":[{"count":5,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions"}],"predecessor-version":[{"id":1397,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions\/1397"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media\/1380"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}