Hello,
IDE: VS .NET 2003.
Problem: Mangled bits of gc class embedded within native C++ class.
Description: I have a gc class, BoxedInfo. This wraps a Value type
structure, NotiInfo. Basically, this structure is imported into MC++ library
from a C# library.
//gc class in MC++
[StructLayout(LayoutKind::Sequential)]
[Serializable]
public __gc class BoxedInfo
{
public:
CSharpLib::NotiInfo m_Info;
BoxedInfo(CSharpLib::NotiInfo anInfo_in) : m_Info(anInfo_in) {}
CSharpLib::NotiInfo unbox() { return m_Info;}
};
//structure in C# library
public struct NotiInfo
{
public Int32 mode;
public Int32 status;
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_I4)]
public Int32[] list;
public Int32 state;
public UInt32 errMsgId;
}
I also have a native C++ class embedding the gc class object pointer
__nogc class CBTemplate
{
public:
CBTemplate();
void notifyGCHandle(BoxedInfo *aInfo);
virtual void notify()=0;
protected:
gcroot<<BoxedInfo*>> m_BoxedInfo;
};
When accessed the bits of m_BoxedInfo from native client, the bits were
mangled.
When safearray type member in imported structure was commented, everything
seemed to be working.
Can you please throw some light on this problem?
If possible Can you please suggest a book that covers C++ Interop issues?
I read on some MSDN articles about the boundary differences in memory layout
between managed and native types. Is the mangled memory problem due to
improper marshaling? Do I have to do custom marshaling to get around this
problem?
Can you please provide an example solution/sample solution link for this
problem?
Many Thanks & Best Regards,