Click to See Complete Forum and Search --> : Calling C from VB


Jim Coleman
February 25th, 2000, 12:41 AM
Hi,

I am trying to call a C/C++ function contained in a DLL. Most of the required C parameters are vectors and matrices. I have tried many alternatives, but when I debug the DLL the VB arrays are not getting passed through to C.

This is not an issue (as far as I know) of decorated names or mangling, the DLL and its exported function is located OK.

I have defined the VB side as " ... ByRef myArray() as double", and the C side as "double *myArray".

If anyone knows how to overcome this it would be much appreciated.

Thanks.

Chris Eastwood
February 25th, 2000, 03:14 AM
I seem to remember somewhere in the VB documentation that you should always pass in the first element of your array to the C DLL.

eg.


lRet = MyCFunction(sSomeArray(0), lSomeOtherValue)




- make sure you know where your arrays start from though!


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb

Ravi Kiran
February 25th, 2000, 05:34 AM
Declare the function like this for double * myArray

Declare Function SomeCFunc(byref lpAr as Double)
and use it like this

dim someAr(100) as Double
SomeCFunc(somear(0)) ' technically
' *myarray is nothing but &myarray(0), right?

You can also try As Any, but it is not necessary because you are not passing a structure.

RK