Converting unmanaged struct -> CLI value struct

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

    #1

    Converting unmanaged struct -> CLI value struct

    I'm having an issue converting an unmanaged struct to a CLI managed
    struct. It's a value struct and this cannot be changed.

    [StructLayout(La youtKind::Seque ntial, CharSet=CharSet ::Ansi, Pack=1)]
    public value struct UpdateItem
    {
    public:

    [MarshalAs(Unman agedType::ByVal TStr, SizeConst=50)]
    System::String ^Name;

    [MarshalAs(Unman agedType::ByVal TStr, SizeConst=50)]
    System::String ^Address;

    [MarshalAs(Unman agedType::ByVal TStr, SizeConst=10)]
    System::String ^Envelope;

    [MarshalAs(Unman agedType::ByVal TStr, SizeConst=30)]
    System::String ^Record;

    virtual System::String^ ToString() override;
    void SetDefaultValue s();
    };

    But I cannot use

    Marshal::PtrToS tructure((IntPt r)&item, UpdateItem_); Because it has
    issues apparently with the fact the managed struct is a value type. I
    could copy these items manually, but this conversion is going to
    happen, quite possible, in excess of 11 times a second, and gcnew'ing
    these four managed strings each time is unacceptable. And I know
    they're managed, and they will get Garbage Collected; but anyone when
    this runs, I promise you the GC isn't running enough for me. The
    memory continues to creep up, and up. Any solutions?

    THank you in advance.

  • Mattias Sjögren

    #2
    Re: Converting unmanaged struct -> CLI value struct

    >But I cannot use
    >
    >Marshal::PtrTo Structure((IntP tr)&item, UpdateItem_); Because it has
    >issues apparently with the fact the managed struct is a value type.
    Use the other PtrToStructure overload.


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    Working...