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>
https://msdn.microsoft.com/en-us/library/office/gg278832.aspx?f=255&MSPPError=-2147217396
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 Declare statement (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:
②LongPtr Data Type
https://msdn.microsoft.com/en-us/library/office/gg251378.aspx?f=255&MSPPError=-2147217396
LongPtr (Long integer on 32-bit systems, LongLong integer on 64-bit systems) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647 on 32-bit systems; and signed 64-bit (8-byte) numbers ranging in value from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 on 64-bit systems.
VBA Excel WideCharToMultiByte Compile error on 64-bit System的更多相关文章
- 一种简单有效的VBA源代码加密办法,支持64位宿主,适用于大部分VBA代码加密
原始出处:http://www.cnblogs.com/Charltsing/p/EncryptVBACode.html VBA代码加密是个老生常谈的问题,自从本人的VBA Dumper发布之后,在O ...
- Data Flow ->> Excel Connection遇到错误:[Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.....
在SSIS下做Excel导入数据的时候遇到下面的错误 [Excel Source [16]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONF ...
- FreeModbus LINUXTCP Compile ERROR
/********************************************************************************* * FreeModbus LINU ...
- OK335xS canutils deal with compile error
/************************************************************************************** * OK335xS ca ...
- Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出
Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...
- Handling CLIK AS3 Compile Error 1152 & 5000
Handling CLIK AS3 Compile Error 1152 & 5000 Action You add a CLIK AS3 component from CLIK_Compon ...
- Android error:No CPU/ABI system image available for this target
原文:Android error:No CPU/ABI system image available for this target No CPU/ABI system image available ...
- error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted
参考: Python pip安装模块报错 Mac升级到EI Captain之后pip install 无法使用问题 error: could not create '/System/Library/F ...
- SecureCRT connecting VM Linux show error message: The remote system refused the connection.
SecureCRT connecting VM Linux show error message: The remote system refused the connection.
随机推荐
- new function
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- WPF: WPF 中的 Triggers 和 VisualStateManager
在之前写的这篇文章 WPF: 只读依赖属性的介绍与实践 中,我们介绍了在 WPF 自定义控件中如何添加只读依赖属性,并且使其结合属性触发器 (Trigger) 来实现对控件样式的改变.事实上,关于触发 ...
- 【Java】多线程初探
参考书籍:<Java核心技术 卷Ⅰ > Java的线程状态 从操作系统的角度看,线程有5种状态:创建, 就绪, 运行, 阻塞, 终止(结束).如下图所示 而Java定义的 ...
- python函数的面向对象——面向对象设计
通过几个函数式编号演进,理解面向对象设计 def01.py dog1 = { 'name':'元昊', 'gender':'母', 'type':'藏獒' } dog2 = { 'name':'李李' ...
- cryptojs的使用
项目中经常会遇到加密解密的需求,这里有一个js库非常好用,就是crypto-js.下面记录一下使用方法. 首先,安装js库 npm install crypto-js --save 然后,在项目中使用 ...
- 可拖动布局之Gridster
看过bootstrap可视化布局系统的人是不是都会对页面元素的拖拽有着很大的兴趣?下面呢,楼主就给大家讲两个楼主知道的拖拽小插件吧. 一.gridster 1.了解gridster 后续官网:http ...
- Spring Data与elasticsearch版本对应关系
- Tomcat输出保存JVM GC日志文件
当系统出现问题时,分析java虚拟机GC日志可以帮助我们定位问题,一般来说, 我们可以通过制定JVM参数使tomcat保存GC日志文件,具体实现如下: Windows下: 找到tomcat的解压目录, ...
- 解决mac 中的myeclipse控制台中文乱码问题
http://www.myexception.cn/eclipse/1742588.html 解决 http://my.oschina.net/u/555006/blog/195013
- java实现 redis的发布订阅(简单易懂)
redis的应用场景实在太多了,现在介绍一下它的几大特性之一 发布订阅(pub/sub). 特性介绍: 什么是redis的发布订阅(pub/sub)? Pub/Sub功能(means Publ ...