{"id":1283,"date":"2023-04-14T14:23:20","date_gmt":"2023-04-14T14:23:20","guid":{"rendered":"https:\/\/262235.xyz\/?p=1283"},"modified":"2023-07-24T14:11:59","modified_gmt":"2023-07-24T06:11:59","slug":"1283","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2023\/04\/14\/1283\/","title":{"rendered":"GPT4: VBA \u4ece 32\u4f4d\u5347\u7ea7\u523064\u4f4d\u540e\uff0c\u4f7f\u7528 WinAPI \u51fd\u6570\uff0c \u51fd\u6570\u58f0\u660e\u7684\u53d8\u5316?"},"content":{"rendered":"<h2>\u76f8\u5173 <a href=\"https:\/\/lyvba.com\/index.php\/archives\/1168\/\">\u5fae\u8f6f\u4e2d\u6587\u6587\u6863 64 \u4f4d Visual Basic for Applications \u6982\u8ff0<\/a><\/h2>\n<p>\u5728\u5c06 VBA \u4ece 32 \u4f4d\u5347\u7ea7\u5230 64 \u4f4d\u540e\uff0c\u4f7f\u7528 WinAPI \u51fd\u6570\u65f6\uff0c\u51fd\u6570\u58f0\u660e\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u66f4\u6539\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4e3b\u8981\u7684\u53d8\u5316\uff1a<\/p>\n<ol>\n<li>\n<p>\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<p>\u5bf9\u4e8e\u6307\u9488\u548c\u53e5\u67c4\uff0c\u9700\u8981\u5c06\u6570\u636e\u7c7b\u578b\u4ece <code>Long<\/code> \u66f4\u6539\u4e3a <code>LongPtr<\/code>\u3002<code>LongPtr<\/code> \u80fd\u591f\u5728 32 \u4f4d\u548c 64 \u4f4d\u7cfb\u7edf\u4e2d\u5206\u522b\u517c\u5bb9 <code>Long<\/code> \u548c <code>LongLong<\/code>\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code>' 32\u4f4d\u7cfb\u7edf\u4e2d\nDeclare Function GetActiveWindow Lib user32 () As Long\n\n' 64\u4f4d\u7cfb\u7edf\u4e2d\nDeclare PtrSafe Function GetActiveWindow Lib user32 () As LongPtr\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u58f0\u660e\u51fd\u6570\u65f6\u6dfb\u52a0 <code>PtrSafe<\/code> \u5173\u952e\u5b57\uff1a<\/p>\n<p>\u5728\u58f0\u660e WinAPI \u51fd\u6570\u65f6\uff0c\u9700\u8981\u5728 <code>Declare<\/code> \u5173\u952e\u5b57\u540e\u6dfb\u52a0 <code>PtrSafe<\/code> \u5173\u952e\u5b57\u3002\u8fd9\u8868\u660e\u51fd\u6570\u5728 64 \u4f4d\u7cfb\u7edf\u4e2d\u662f\u517c\u5bb9\u7684\u3002<\/p>\n<p>\u793a\u4f8b\uff1a<\/p>\n<pre><code>' 32\u4f4d\u7cfb\u7edf\u4e2d\nDeclare Function GetWindowText Lib user32 Alias GetWindowTextA (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long\n\n' 64\u4f4d\u7cfb\u7edf\u4e2d\nDeclare PtrSafe Function GetWindowText Lib user32 Alias GetWindowTextA (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u517c\u5bb9\u6027\uff1a<\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u4ee3\u7801\u5728 32 \u4f4d\u548c 64 \u4f4d\u7cfb\u7edf\u4e0a\u5747\u53ef\u8fd0\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u7f16\u8bd1\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>#If VBA7 Then\n  Declare PtrSafe Function GetActiveWindow Lib user32 () As LongPtr\n#Else\n  Declare Function GetActiveWindow Lib user32 () As Long\n#End If\n\n\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528 VBA7 \u6761\u4ef6\u7f16\u8bd1\u6307\u4ee4\u6765\u68c0\u67e5 VBA \u7248\u672c\u3002VBA 7 \u5f15\u5165\u4e86 64 \u4f4d\u652f\u6301\uff0c\u56e0\u6b64\u5982\u679c VBA \u7248\u672c\u4e3a 7 \u6216\u66f4\u9ad8\uff0c\u5219\u4f7f\u7528 PtrSafe \u548c LongPtr\u3002<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0c\u5728\u5c06 VBA \u4ece 32 \u4f4d\u5347\u7ea7\u5230 64 \u4f4d\u540e\uff0c\u9700\u8981\u6ce8\u610f\u6570\u636e\u7c7b\u578b\u7684\u66f4\u6539\u3001\u6dfb\u52a0 <code>PtrSafe<\/code> \u5173\u952e\u5b57\u4ee5\u53ca\u786e\u4fdd\u4ee3\u7801\u7684\u517c\u5bb9\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u5173 \u5fae\u8f6f\u4e2d\u6587\u6587\u6863 64 \u4f4d Visual Basic for Applications \u6982\u8ff0 \u5728\u5c06 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[67],"class_list":["post-1283","post","type-post","status-publish","format-standard","hentry","category-learn","tag-vba"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1283","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=1283"}],"version-history":[{"count":1,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1283\/revisions"}],"predecessor-version":[{"id":1378,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/1283\/revisions\/1378"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=1283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=1283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=1283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}