VBA Excel WideCharToMultiByte Compile error on 64-bit System

Compile Error:

The code in this project must be updated for use on64-bit systems.

Please review and update Declare statements and then mark them with the PtrSafe attribute.

1.问题:

32-bit的VBA程序,在64-bit系统上运行时,出现该编译错误。

环境:Office2010 Excel 64-bit, 64-bit Win7 OS

?

2.原因

原程序中,函数声明如下。该函数在32-bit系统中编译、运行没有问题。但是在64-bit系统中会出现编译错误。

Private Declare Function WideCharToMultiByte Lib "kernel32" _

(ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Integer, ByVal cchWideChar As Long, _

lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

?

3.修改

其实,提示信息中,已经说明的很清楚了。

只要在函数的声明处添加"PtrSafe"属性(无需修改其他地方),程序就正常了。

修改后程序:

Private Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" _

(ByVal CodePage As Long, ByVal dwFlags As Long, lpWideCharStr As Integer, ByVal cchWideChar As Long, _

lpMultiByteStr As Byte, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long

?

4.扩展

①PtrSafe<Keyword>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。