CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2001
    Posts
    4

    Passing an array to a DLL procedure

    Hello,

    I am creating a DLL object in which I am creating a function which does some manipulation on the array passed to it. I am calling the function from another VB EXE project. The type of the array in the calling file is Variant(). When the function is called, it is giving an error 'Type Mismatch'. How do pass an array to the function? Please help me.

    Thanks in advance
    Hitesh


  2. #2

    Re: Passing an array to a DLL procedure

    do U try in this way?

    dim myobj as new mylib.myclass

    dim myarray(10) as variant
    'also U can declare dim myarray(10)

    'possible code for filling or initializing myarray

    myobj.method_with_array(myarray)

    hi,brt


    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  3. #3
    Join Date
    Jul 2001
    Posts
    4

    Re: Passing an array to a DLL procedure

    Hello,

    The size of the array is not fixed. It is derived at the runtime. In such a case how do I define the array?

    Thanks
    Hitesh


  4. #4

    Re: Passing an array to a DLL procedure

    dim my_array() 'define an empy array

    redim my_array(10) 'define a new dimension for array with lost of data.

    redim preserve my_array(10) 'define a new dimension for array without lost of data (this method is very heavy)

    hi,brt

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  5. #5
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Passing an array to a DLL procedure

    Try passing the first element of the array only. This should pass a refference to the array. I know this is how you must pass an array to a C++ function.

    If that doesn't help, there's something else worth trying. Variants and objects can be arrays themselves. So try passing it as a variant or object rather than an array
    Of course, make sure that the function being called accepts the appropriate datatype.

    Dim myarray(10) as variant
    dim myvar as variant

    ' pass first element
    Call SomeFunction(myArray(0))

    ' Pass an array
    myvar = myArray
    Call SomeFunction(myvar)

    ' pass an object
    set myObject = myvarray
    Call SomeFunction(myObject)




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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