I'm trying to do an interop to a C# structure from C++.
The structure c#
public static IntPtr tempNode = IntPtr.Zero;
and also i am using Marshal.PtrToStructure, Marshal.PtrToStringAuto as per requirement.
now i am trying with 64bit compiled exe, the address shared from c++ to c# is correct, but the functions
Marshal.PtrToStructure, Marshal.PtrToStringAuto are shifting the data within the structure, and filling junk values.
out of 8 bytes, only 4 bytes are copied/correct.
What I have tried:
Node is an structure in my code
public struct NODE
{
public ulong ullSector;
public ulong ullSize;
unsafe public NODE* pNext;
unsafe public NODE* pChild;
unsafe public NODE* pParent;
public uint dwID;
public uint dwSelfNum;
public uint dwParentNum;
public IntPtr pwcName;
public ushort wCT;
public ushort wAT;
public byte bStatus;
public byte bMarked;
public byte bNameLength;
public byte bIsThisRAWFolderFile;
public IntPtr Path;
}
IntPtr tempNode = IntPtr.Zero;
NODE _dynamicNode = (NODE)Marshal.PtrToStructure(tempNode, typeof(NODE));
if i do like these it shifting the data within the structure, and filling junk values.
out of 8 bytes, only 4 bytes are copied
if run in 32 bit then there is no problem in 64 only having this issue.