English 中文(简体)
B. 利用PtrToStructure在C#中进行双亲档案化
原标题:Binary File Deserialization using PtrToStructure in C#

我试图在我公司扭转一个遗产双常数据库,以便我能够将其变成一个更持久的形式。 我们用于创建这一数据的申请已不再得到支持。

我已经指出,我可以描述一系列结构中的数据,我能够用沼泽地把这些数据带到一个管理的环境中。 Ptr ToStructure,但档案除外。

下面,我引述了我试图教化的结构样本。 原始数据完全是按顺序排列的,我正试图分一步淡化。

[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct DrillTPD
{
    public short Header;
    public short Header2;
    public short Header3;
    public short RecordCount;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 999)]
    public TPDHeader[] Templates;
} 
[StructLayout(LayoutKind.Sequential, Pack = 1, Size=18)]
struct TPDHeader
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
    public string TemplateName;
    public int TPDIndex;
}

TPDIndex从档案开始便被冲抵。 我如何增加财产,以适当淡化这一数据?

[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 76)]
struct TPDParent
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 9)]
    public string TemplateName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 25)]
    public string Description;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
    public string Field;
    public double Width;
    public double Length;
    public double Thickness;
    public short WL;
    public short XY;
    public short Origin;
    public short Features;
    [MarshalAs(UnmanagedType.ByValArray)]
    public TPDDetail[] Details;
}
[StructLayout(LayoutKind.Sequential, Pack=1, Size=350)]
struct TPDDetail
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 350)]
    public string Text;
}

TPDParent的TPDDetail阵列由结构的特征界定。 如果没有特征,在TPDParent之后没有数据。

我怎么能动态地让航天员了解图西混凝土阵列的规模?

An pseudo XML 这一数据的结构最好像:

<DrillTPD>
    <TPDHeader>
        <TPDParent>
            <TPDDetail/>
            <TPDDetail/>
            <TPDDetail/>
        </TPDParent>
    </TPDHeader>
    <TPDHeader>
        .....
    </TPDHeader>
</DrillTPD>

最后一项评论: 我只做了工作。 NET语言,但我试图了解未经管理的方面。 感谢您的答复:

问题回答

Try creating a simple instance of your structure hierarchy and then persist it out to a file as bytes. Then you can use a hex editor to compare what you have output against what you thought it would output. The difference will highlight where it is not working as you expect.

否则,你就试图确定你结构的完美定义,并将拒绝工作,直到这一定义完美无缺,而且很难像你所做的那样,实现一个复杂的结构。

如果你有两个班级,即一个有未管理数据的输入组和一个只有管理数据的第二班,一个建筑商将投入类别作为参数,并因此标明序列化,那么如果所有数据都得到管理,那么阵列的规模将由框架内部管理。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签