strucure with buffer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Heger

    #1

    strucure with buffer

    Hi

    An API-Function I want to use needs a structure as parameter:

    public structure myStruct
    dim i1 as short
    dim i2 as byte
    dim i3 as integer
    dim buffer as byte()
    end structure

    buffer is an array of fixed length. But how could I correctly declare
    buffer, so that is really behind i3 in memory? <VBFixedArray(5 12)> doesn't
    work in that case, and declaring b1, b2, b3, b4,... as byte does work, but
    who wouild really want to do that.
    Any ideas?

    thanks

    Ralph


  • Ken Tucker [MVP]

    #2
    Re: strucure with buffer

    Hi,

    Redim buffer after you create the structure.

    Dim m As myStruct
    ReDim m.buffer(512)


    Ken
    --------------------
    "Ralph Heger" <ralph.heger@so ftart.at> wrote in message
    news:43422fd7$0 $11203$79720d31 @newsreader.ino de.at...[color=blue]
    > Hi
    >
    > An API-Function I want to use needs a structure as parameter:
    >
    > public structure myStruct
    > dim i1 as short
    > dim i2 as byte
    > dim i3 as integer
    > dim buffer as byte()
    > end structure
    >
    > buffer is an array of fixed length. But how could I correctly declare
    > buffer, so that is really behind i3 in memory? <VBFixedArray(5 12)> doesn't
    > work in that case, and declaring b1, b2, b3, b4,... as byte does work, but
    > who wouild really want to do that.
    > Any ideas?
    >
    > thanks
    >
    > Ralph
    >
    >[/color]


    Comment

    • Ralph Heger

      #3
      Re: strucure with buffer

      Thanks, Ken

      I have got a solution from an other usegroup. The problem with your solution
      is, that you can't be sure that the memory that 'buffer' needs is on the
      wright location. But declaring buffer with
      '<MarshalAs(Unm anagedType.ByVa lArray, SizeConst := 512)>' does the job.

      thanks
      Ralph



      "Ken Tucker [MVP]" <vb2ae@bellsout h.net> schrieb im Newsbeitrag
      news:eCPlA%23My FHA.612@TK2MSFT NGP10.phx.gbl.. .[color=blue]
      > Hi,
      >
      > Redim buffer after you create the structure.
      >
      > Dim m As myStruct
      > ReDim m.buffer(512)
      >
      >
      > Ken
      > --------------------
      > "Ralph Heger" <ralph.heger@so ftart.at> wrote in message
      > news:43422fd7$0 $11203$79720d31 @newsreader.ino de.at...[color=green]
      >> Hi
      >>
      >> An API-Function I want to use needs a structure as parameter:
      >>
      >> public structure myStruct
      >> dim i1 as short
      >> dim i2 as byte
      >> dim i3 as integer
      >> dim buffer as byte()
      >> end structure
      >>
      >> buffer is an array of fixed length. But how could I correctly declare
      >> buffer, so that is really behind i3 in memory? <VBFixedArray(5 12)>
      >> doesn't work in that case, and declaring b1, b2, b3, b4,... as byte does
      >> work, but who wouild really want to do that.
      >> Any ideas?
      >>
      >> thanks
      >>
      >> Ralph
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Dennis

        #4
        Re: strucure with buffer

        Can you use:

        <StructLayout(L ayoutKind.Seque ntial)> _
        Public Structure MyStructure
        .....

        --
        Dennis in Houston


        "Ralph Heger" wrote:
        [color=blue]
        > Thanks, Ken
        >
        > I have got a solution from an other usegroup. The problem with your solution
        > is, that you can't be sure that the memory that 'buffer' needs is on the
        > wright location. But declaring buffer with
        > '<MarshalAs(Unm anagedType.ByVa lArray, SizeConst := 512)>' does the job.
        >
        > thanks
        > Ralph
        >
        >
        >
        > "Ken Tucker [MVP]" <vb2ae@bellsout h.net> schrieb im Newsbeitrag
        > news:eCPlA%23My FHA.612@TK2MSFT NGP10.phx.gbl.. .[color=green]
        > > Hi,
        > >
        > > Redim buffer after you create the structure.
        > >
        > > Dim m As myStruct
        > > ReDim m.buffer(512)
        > >
        > >
        > > Ken
        > > --------------------
        > > "Ralph Heger" <ralph.heger@so ftart.at> wrote in message
        > > news:43422fd7$0 $11203$79720d31 @newsreader.ino de.at...[color=darkred]
        > >> Hi
        > >>
        > >> An API-Function I want to use needs a structure as parameter:
        > >>
        > >> public structure myStruct
        > >> dim i1 as short
        > >> dim i2 as byte
        > >> dim i3 as integer
        > >> dim buffer as byte()
        > >> end structure
        > >>
        > >> buffer is an array of fixed length. But how could I correctly declare
        > >> buffer, so that is really behind i3 in memory? <VBFixedArray(5 12)>
        > >> doesn't work in that case, and declaring b1, b2, b3, b4,... as byte does
        > >> work, but who wouild really want to do that.
        > >> Any ideas?
        > >>
        > >> thanks
        > >>
        > >> Ralph
        > >>
        > >>[/color]
        > >
        > >[/color]
        >
        >
        >[/color]

        Comment

        Working...