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

    TypeCast in VB??

    Referring to the Code below, how would you retrieve the structure of 'a' back from its memory address stored in the the ItemData Property of a ListBox (or any other control.) CopyMemory and MoveMemory will not work because of the strings/arrays of string stored in the structure. Is there a way to TypeCast a value in VB? Or is there any other way to store a structure in the ItemData
    Property of a ListBox that is retrievable?

    Thanks, Trent

    Dim tArr() As String

    Type t
    i As Integer
    s As String
    arr As tArr
    End Type

    Dim a As t, b As t

    Private Function SomeFunc
    Dim lb As ListBox, nSize As Long
    Dim SomeArray() As String

    Redim SomeArray(10)

    ' Input Dummy Values
    a.i = 1
    a.s = "One"
    a.arr = SomeArray

    lb.AddItem vbNullString ' Add a blank item to the List Box
    lb.ItemData(0) = VarPtr(a) ' Add a pointer to the Structure a to the ItemData proprerty using varPtr

    b = lb.ItemData(0) ' ? Incompatible data types
    nSize = len (b) ' Get the size of the data structure.
    b = CopyMemory(b, lb.ItemData(0), nSize) ' Takes this as a literal 'Long' instead of a structure

    End Function



  2. #2
    Join Date
    Apr 1999
    Location
    Netherlands
    Posts
    181

    Re: TypeCast in VB??

    Don't know if it helps.... but in a subclass dll, I use Objptr to save a pointer to the class that is maintaining the subclass, I use copymemory in the subclass function to restore the pointer to that class to a class of that type so I can call a specified function in that class (which will raise an event) and that works perfectly... maybe you can change the type to a class and try it with that. (hope this makes sense....)

    Crazy D @ Work :-)

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