2016-10-02 23 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