Results 1 to 3 of 3

Thread: Getting Data?

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Getting Data?

    I have a IntPtr that points to a byte array in unmanaged memory.

    How can i copy this to a managed byte array or structure?
    Last edited by <ABX; Mar 2nd, 2004 at 04:09 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    you probably need to look up Marshal attributes . PtrToStructure is what you're looking for *maybe* .

  3. #3

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    ok, heres the structure

    VB Code:
    1. <StructLayout(LayoutKind.Sequential)> _
    2.     Public Structure TOC
    3.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _
    4.         Dim TOC_LEN() As Byte
    5.         Dim FirstTrack As Byte
    6.         Dim LastTrack As Byte
    7.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=800)> _
    8.         Dim TrackInfo() As Byte
    9.     End Structure

    VB Code:
    1. 'Heres where the buffer is allocated
    2.  
    3.         Dim xTOC as new TOC
    4.  
    5.         Dim memptr As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(xToc))
    6.  
    7.         Marshal.StructureToPtr(xToc, memptr, False)
    8. 'This is now passed to a api call to be filled

    VB Code:
    1. 'Heres where i try to read the data the was put intot the structure by the api call
    2.  
    3.             Dim Data As TOC = CType(Marshal.PtrToStructure(psrb.SRB_BufPointer, GetType(TOC)), TOC)
    4.  
    5. 'none of the values in data are set???
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

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