CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2000
    Posts
    3

    Calling C from VB

    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.


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Calling C from VB

    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

  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: Calling C from VB

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured