Results 1 to 12 of 12
  1. #1
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing User-Defined Types to a DLL Procedure (VB6)

    Edited by HansV to make URL clickable

    Hi, I'm struggling with a problem in VB6. I'm use to the C world, so I'm on thin ice here. From our VB6 We make use of a C++ DLL and call functions with custom arguments. That works fine by define a type in VB6 and transfere that as reference to C++, as the same struct defined there. That is right after the book: http://msdn.microsoft.com/en-us/libr...32(VS.60).aspx

    The problem is now that we need to enlarge the Type to more that the 64Kbyte of static data that the VB6 compiler can handle... how is this done best?
    I've tried to just make a empty array in type and then ReDim the array so it is not allocated until runtime .. that gives me an error by just crashing the VB studio .. not even a error note ..
    Any ideas or hints ??
    /Søren

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Can't you use Visual Basic 2008? The .Net version of VB doesn't have the 64K limitation, as far as I know.

    (Note: users would need to install the .Net Framework in order to run your application.)

  3. #3
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Hi Hans
    No, unfortunately this code is part of a very big and complex 10 year development, so the upgrade to a newer compiler would give a lot of other issues.
    I think the theory with this is right .. I'm just missing something litle and stupid ..
    /Søren

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    I'm sorry, I can't help you with that; I hope that someone else will have a helpful suggestion.

  5. #5
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Can anyone give a short explanation of how to allocate memory in VB6?
    Is it possible to declare a type with a empty array inside, and later at runtime ReDim it to a large content?
    /Søren

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)


  7. #7
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Hi Hans, the ReDim still doesn't work. As I read it, the ReDim is made for Arrays but in this case the compiler comes up with an error on run time "Compile error: Array already dimensioned". To get on here is my code/problem:

    Private Const LIST_FELTAEN_FELT_NR_LAENGDE = 5
    Private Const LIST_FELTAEN_VAERDI_LAENGDE = 31
    Private Const LIST_FELTAEN_FELT_TYPE_LAENGDE = 3
    Private Const LIST_FELTAEN_FELT_TEKST_LAENGDE = 71

    Type TTYPE__BJFLA05O_ELM
    Id As Long
    Vaerdi As String * LIST_FELTAEN_VAERDI_LAENGDE
    FeltNr As String * LIST_FELTAEN_FELT_NR_LAENGDE
    Indkomstaar As Long
    Skatteyderart As Long
    Felttype As String * LIST_FELTAEN_FELT_TYPE_LAENGDE
    Felttekst As String * LIST_FELTAEN_FELT_TEKST_LAENGDE
    FeltLaengde As Long
    Fortegnsregel As Long
    BrevtekstId As Long
    AendringsType As Long
    AendrRowVer As Long
    FeltRowVer As Long
    GrundlRowVer As Long
    End Type

    Public Const BJFLA05O_ELM_NO_OF_ELMS = 90
    Type TTYPE_BJFLA05O
    SagsId As Long
    ' Afsluttet As Long
    MaxItemsBuffer As Long ' Dette felt Skal manuelt saettes til BJFLA05O_ELM_NO_OF_ELMS!
    NoOfItems As Long
    ResultBuffer(0 To BJFLA05O_ELM_NO_OF_ELMS -1) As TTYPE__BJFLA05O_ELM
    End Type

    The Resultbuffer need to be larger, but here the VB6 compiler is limited to 64Kbyte.

    As a ReDim on runtime dosen't seem to work, I have tried to make the TTYPE_BJFLA050 to a Class, to get rid of the static memory allocation. This gives me another challenge. The Get/LET properties works fine with the Long members, but with the custom Array it dosen't work as I'm use to in C#. Can't VB6 take an custom Array in an custom class ?
    /Søren "the VB6 illiterate"

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    I'm sorry, this is far outside my scope. I hope that someone else can help you with this.

  9. #9
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Thanks anyhow Hans .. I know I'm asking C questions to VB .. the mixup is properly wrong..
    /Søren

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    You can't redim it it because you declared it as a fixed size array to start with. Your type would need to be:
    <pre>Type TTYPE_BJFLA05O
    SagsId As Long
    ' Afsluttet As Long
    MaxItemsBuffer As Long ' Dette felt Skal manuelt saettes til BJFLA05O_ELM_NO_OF_ELMS!
    NoOfItems As Long
    ResultBuffer() As TTYPE__BJFLA05O_ELM
    End Type</pre>

    for the Redim to work. I'm not sure exactly what problem you are having with the array in the class - can you post the code you tried?
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Hi Rory .. Tried the empty array as well .. In the sub using the Type I'm not getting any compiler errors by using:
    ReDim BJFLA05O.ResultBuffer(180, 1) As TTYPE__BJFLA05O_ELM
    or
    ReDim BJFLA05O.ResultBuffer(180) As TTYPE__BJFLA05O_ELM

    but on run time the hole visual basic just crashes without any warning by calling: BJFLA04__ListFltaend(BJFLA05O, DLLErrObject, False), witch is a function in a C++ DLL. I'm working on how to get an error message with this ..
    /Søren

  12. #12
    New Lounger
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing User-Defined Types to a DLL Procedure (VB6)

    Solution .. I think I figured out the solution to the ReDim error.
    It is used in a VB6 program there calls a C++ DLL. The parameters are given ByRef so they are of the same Type/Struct and therefor the C++ part can use the same struct at the same memory adr. But .. When I give a Struct with a empty and on runtime gives the size of the array, C++ miss the pointer to this adr. Therefor there should be a "sub ReDim" to the array.

    Well .. That was the teori .. Now I'm only have to implement it .. ;oP
    /Søren

Posting Permissions

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