2

I have VBA program running on Excel 64-bit calling some DLL functions (C++). The problem is (apparently) it can't pass pointers to C++ program. The program works with Excel 32-bit.The operating system is Windows 8. For Windows 7 both 32-bit and 64-bit versions of Excel are working well.

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)

It returns -88.

1
  • 1
    Try Dim x As LongPtr Commented May 27, 2015 at 16:54

1 Answer 1

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

LongPtr evaluates to Long in 32-Bit environments and to LongLong in 64-Bit environments so defining x as such should work.

Addtionally, CLng will ensure 1 is evaluated as a Long type. If this is not added VBA will assume you mean Integer

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.