PtrSafe

办公室终于换新电脑了,我那08年的老机器终于退役了……大哭

好吧,新机器8G内存,果断上64位系统

运行之前写的vba小程序,嗯?!提示要增加PtrSafe,去查了一圈,原来是这么回事儿啊

https://msdn.microsoft.com/zh-cn/library/gg278832.aspx

PtrSafe <keyword>

Office 2013

Last modified: December 06, 2011

Applies to: Office 2013 | VBA

The PtrSafe keyword is used in this context:

Declare Statement

Note Note

Declare statements with the PtrSafe keyword is the recommended syntax. Declare statements that include PtrSafe work correctly in the VBA7 development environment on both 32-bit and 64-bit platforms only after all data types in the Declarestatement (parameters and return values) that need to store 64-bit quantities are updated to use LongLong for 64-bit integrals or LongPtr for pointers and handles. To ensure backwards compatibility with VBA version 6 and earlier use the following construct:

VBA
#If Vba7 Then 
Declare PtrSafe Sub... 
#Else 
Declare Sub... 
#EndIf

When running in 64-bit versions of Office Declare statements must include the PtrSafe keyword.

The PtrSafe keyword asserts that a Declare statement is safe to run in 64-bit development environments.

Adding the PtrSafe keyword to a Declare statement only signifies the Declare statement explicitly targets 64-bits, all data types within the statement that need to store 64-bits (including return values and parameters) must still be modified to hold 64-bit quantities using either LongLong for 64-bit integrals or LongPtr for pointers and handles.


PtrSafe <keyword>

Office 2013

上次修改时间: 2011年12月6日

适用范围: Office 2013 | VBA

将"PtrSafe"关键字用于以下上下文:

Declare 语句

注释 注释

含"PtrSafe"关键字的 Declare 语句是推荐的语法。包含"PtrSafe"的 Declare 语句在 32 位和 64 位的平台上的 VBA7 开发环境中正常工作,只是要在需要存储 64 位数量的"Declare"语句(参数和返回值)中的所有数据类型被更新以将 LongLong 用于 64 位整数,或将LongPtr 用于指针和句柄。为了确保 VBA 版本 6 和更早版本的向后兼容性,请使用以下构造:

VBA
#If Vba7 Then 
Declare PtrSafe Sub... 
#Else 
Declare Sub... 
#EndIf

当在 Office 的 64 位版本中运行时,"Declare"语句必须包括"PtrSafe"关键字。

"PtrSafe"关键字断定"Declare"语句在 64 位的开发环境中运行是安全的。

将"PtrSafe"关键字添加到"Declare"语句只表明了"Declare"明确地以 64 位为目标,必须修改该语句中的所有需要存储 64 位的数据类型(包括返回值和参数)以通过将 LongLong 用于 64 位整数或将 LongPtr 用于指针和句柄来保留 64 位数量。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码修正:Option Explicit Private Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare PtrSafe Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare PtrSafe Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare PtrSafe Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare PtrSafe Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare PtrSafe Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare PtrSafe Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long Private Declare PtrSafe Function EmptyClipboard Lib32" () As Long Private Declare PtrSafe Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long Private Const CF_BITMAP = 2 Private Const SRCCOPY = &HCC0020
07-25

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值