View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Problems with callback from DLL invoked from VBA

I'm not sure what the problem is. I suspect that it is because
VB/VBA uses SAFEARRAY structures rather than C-type arrays. You
might have more luck posting this in one of the Visual C
newsgroups.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Jag Man" wrote in message
...
Yes, that works. Thanks, Chip.

Now, moving closer to what I really need to do, I need to add

an
array argument to the callback function:

long __stdcall tryCB3(long n,long(__stdcall *cbFunc)(long m,

long *))
{
...
long* x= new long[n];
...
r = cbFunc(n, x);
..

delete [] x;
return r;
}

And in the VB:

Public Function theCBFunc4(ByVal m As Long, ByRef x() As Long)

As Long
Dim i As Integer
Dim s As Long
s = 0
For i = 0 To m - 1
s = s + x(i)
Next i
theCBFunc4 = s
End Function

But, it doesn't work. It crashes Excel when I call the tryCB3

function from
VB.

Any ideas?

TIA

Ed