2016-10-02 40 views
0

在今天通过更新获得的OSX上新的64位版本的Excel 2016中,条件编译在检查没有的函数定义时似乎没有遵循PtrSafe已定义(对于32位平台将是这种情况)。在这个例子中,我们对不同平台的相同函数有不同的定义,并且当Excel加载插件时,它会死掉,并且抱怨函数声明中没有PtrSafe的第三个定义(但它当然不是因为它适用于32位平台)。带有32位标志的Excel 2016条件编译

有没有什么办法让Excel在VBA中遇到这样的代码时不会死?或者这仅仅是OSX上的64位Excel 2016中的一个错误?看起来像是一个明显的bug。我在哪里报告Excel中的错误?

#If Mac Then 
' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name 
Private Declare PtrSafe Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#ElseIf Win64 Then 
Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_xls_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#Else 
Private Declare Function get_global_param_string_private Lib "CoolProp_xls_std.dll" Alias "[email protected]" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#End If 

This is the error from Excel

回答

1

除非API函数本身是64和32就足够了使用VBA7开关(开始于Office 2010中)的Windows位Windows不同:

#If Mac Then 
' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name 
Private Declare PtrSafe Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#ElseIf VBA7 Then 
Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_xls_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#Else 
Private Declare Function get_global_param_string_private Lib "CoolProp_xls_std.dll" Alias "[email protected]" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long 
#End If 
+0

那并不如果你使用的是Excel 2010或更高版本,ptrsafe关键字可用于任何位数,那么回答这个问题的方法与擅长混淆没有ptrsafe的函数有关,因为它们适用于32位平台 – ibell

+0

。有关更多信息,请参阅http://www.jkp-ads.com/articles/apideclarations.asp。 – jkpieterse

+0

我不知道那个!感谢有关在此支持的版本的信息 – ibell