Marshalling: GCHandle Pinning vs Marshal.PtrToStruct & StructToPtr?

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

    #1

    Marshalling: GCHandle Pinning vs Marshal.PtrToStruct & StructToPtr?

    I am calling legacy Btrieve database functions using StructureToPtr and
    PtrToStructure, but I think that I am getting memory corruption from improper
    marshalling, and I am unclear about when memory is being copied vs memory
    being pinned. Does StructureToPtr pin, or just copy?

    I've seen references to pinning memory using GCHandles while googling the
    topic, and I suspect that I might do better using GCHandle functions rather
    than Marshal functions since these buffers are reused often. I've spent hours
    on google trying to get a better understanding, but I'm still in a fog. Which
    is the best approach for calling old C++ DLLs?

Working...