I just submitted a case to Ms at noon. The problem is described as follows:
(This is an open-source Excel file. Code It was originally written in VB.net, and I wrote it again in C. The API used in VB.net: fileput does not solve this problem. I wrote this myself, but it does not work .)
The followingMarshal. sizeof (VT)In this line of codeSizeIt should be2 + 2 + 1Instead of memory alignment6. How can I get5This value?
Private VoidFileput (system. valuetype VT)
{
IntSize = 0;
Size = marshal. sizeof (VT );
Intptr P = marshal. allochglobal (size );
Marshal. structuretoptr (Vt, P,True);
Byte[] Buf =New Byte[Size];
Marshal. Copy (p, Buf, 0, size );
FS. Write (BUF, 0, Buf. Length );
}
//Call code:
L = aformat [lindex]. length;
Cformat_record.opcode = 0x1e;
Cformat_record.length = (Short) (L + 1 );
Cformat_record.formatlength = (Byte) (L );
Fileput (cformat_record );
//Structure example
[Structlayoutattribute (layoutkind. Sequential, charset = charset. Auto)]
StructFormat_record
{
Public ShortOpcode;// 0x1e
Public ShortLength;// 1 + Len (Format)
[Financialas (unmanagedtype. u1, sizeconst = 1)]Public ByteFormatlength;// Len (Format)
}// Followed by the format-picture
After Ms replies to me, I will post the results to share with you.