首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c++ C# struct 变换

2014-01-01 
c++ C# struct 转换c++ structtypedef struct _GLYDEPOSITCOUNTER {unsigned int EventNumberstruct tm T

c++ C# struct 转换

c++ struct

typedef struct _GLYDEPOSITCOUNTER {
unsigned int EventNumber;
struct tm Time;
unsigned int dwSquentialNo;
unsigned int dwUserID;
GLYCOUNTERS DepositData;
} GLYDEPOSITCOUNTER, *LPGLYDEPOSITCOUNTER;


struct tm Time;
Each data range is as described below.
tm_year: 2000 to 2099, tm_mon: 1 to 12, tm_mday: 1 to 31,
tm_hour: 0 to 23, tm_min: 00 to 59, tm_sec: 00 to 59

头文件里没有介绍这个struct tm Time,
文档里只是说了它的取值范围。
我现在的c#转换是:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct Time
    {
        public uint tm_year;
        public uint tm_mon;
        public uint tm_mday;
        public uint tm_hour;
        public uint tm_min;
        public uint tm_sec;
    }

转换出来的结果和上面介绍的取值不一样,我想肯定转换错了,请高手们帮忙,多谢。




[解决办法]
struct tm的定义在<time.h>中,是9个int。


struct tm {
        int tm_sec;     /* seconds after the minute - [0,59] */
        int tm_min;     /* minutes after the hour - [0,59] */
        int tm_hour;    /* hours since midnight - [0,23] */
        int tm_mday;    /* day of the month - [1,31] */
        int tm_mon;     /* months since January - [0,11] */
        int tm_year;    /* years since 1900 */
        int tm_wday;    /* days since Sunday - [0,6] */
        int tm_yday;    /* days since January 1 - [0,365] */
        int tm_isdst;   /* daylight savings time flag */
        };

热点排行