2015-05-27 103 views
2

我有VBA程序運行在Excel 64位調用某些DLL函數(C++)。問題是(顯然)它不能傳遞指向C++程序的指針。該程序適用於Excel 32位。操作系統是Windows 8。對於Windows 7,Excel的32位和64位版本都運行良好。VBA 64位Excel不傳遞指向DLL函數的指針(C++)

C++:

double test(long* v, long i) 
{ 
    if (v == NULL) 
     return -88; 
    else 
     return *((long*)v); 
} 

VBA:

Private Declare PtrSafe Function hamid_test Lib "...\CVode.dll" (ByVal v As LongPtr, ByVal i As Long) As Double 

Dim x As LongLong 
Dim z As Double 
z = test(x, 1) 

它返回-88

+1

嘗試'Dim x As LongPtr' – kaybee99

回答

1
Dim x As LongPtr 
Dim z As Double 
z = test(x, CLng(1)) 

LongPtr評估爲Long在32位的環境,並在如此x限定爲這樣的64位的環境LongLong應該工作。

另外,CLng將確保1被評估爲Long類型。如果沒有添加,VBA將假設你的意思是Integer