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

    what datatype to pass to DLL?

    Hi!

    I want to call a function in a DLL (written in C++). One of the arguments expected is of type "array of void pointers".

    When passing the datatype "IntPrt" from VB.net, the 4 element size array from VB.net is truncated to a one element size array after the call.

    What argument should be passed from VB.net to handle "arrays of void pointers"??

    Thanks!!!

    Adri Gerritsen

  2. #2
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: what datatype to pass to DLL?

    an array of void pointers would be a pointer of pointer to me.. so a pointer to the first address of your structure would be good.
    Nicolas Bohemier

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: what datatype to pass to DLL?

    Here some code: C++ DLL code
    Code:
    //a C++ dll function taking an array
    int _stdcall FillArr(int * inArr, int ArrSize) {
        int LoopArr; // Loop variable
    
        // Make sure they didn't pass anything silly
        if (ArrSize < 1) return 0;
    
        // Fill the array
        for (LoopArr = 0; LoopArr < ArrSize; LoopArr++) {
            inArr[LoopArr] = LoopArr;
        }
    
        // Return 1 if all went well
        return 1;
    }
    Here the VB code:
    Code:
    'VB code which calls the dll function.
    Private Sub Form_Load()
        Dim MyArr() As Long
        Dim ArrSize As Long
        Dim LoopArr As Long
        Dim MakeString As String
    
        ' Create the array
        ArrSize = 10
        ReDim MyArr(ArrSize - 1) As Long
    
        ' Get the DLL to fill the array
        ' Note here that we pass the first entry of the array and not the
        ' array pointer itself, this is to make sure we fill the array
        ' data and not overwrite the array descriptor by mistake.
        Call MsgBox(FillArr(MyArr(0), ArrSize))
    
        ' Loop through the new array contents and make a string message
        For LoopArr = 0 To ArrSize - 1
            MakeString = MakeString & MyArr(LoopArr) & vbCrLf
        Next LoopArr
    
        ' Report array contents
        Call MsgBox(MakeString)
    End Sub
    The point to note here is that we pass the first entry of the array and not the array pointer itself, this is to make sure we fill the array data and not overwrite the array descriptor by mistake. This seems to be the issue with your code. Hope this helps.

    If not then please paste some code so that we can have a look at what is happening.

    Here are some links to some good articles upon this:
    1. MSDN - How To Pass Arrays Between Visual Basic and C
    2. FlipCode - Interfacing Visual Basic And C++
    3. Passing Arrays to a DLL

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