c++结构体转换成c#

msdnsyh 2010-03-08 10:34:50
请教如题

typedef struct TagMosaicDataFileHeader
{
unsigned short iVersion; //格式版本号 1,2,- 2字节
char Hold1[14];//保留14个字节
char cSiteName[20];//区域名称/雷达站名 20个字节
char strDataType[4];//数据类型 -4 Bytes
unsigned short TotalRadarStationNum;//组网区域内雷达站数
unsigned short int nYear;//观测开始日期--年
unsigned short int nMonth;
unsigned short int nDay;
unsigned short int nHour;
unsigned short int nMinute;
int nStartLongitude; //数据开始经度,度×1000
int nStartLatitude;//数据开始纬度,度×1000
int nEndLongitude; //数据终止经度,度×1000
int nEndLatitude;//数据终止纬度,度×1000
unsigned short int nStartHeight;//数据起始高度(m)
unsigned short int nEndHeight;//数据终止高度(m)
unsigned short int nXNumGrids;//经度方向格点数
unsigned short int nYNumGrids;//纬度方向格点数
unsigned short int nZNumGrids;//数据层数
unsigned int nXResolution;//数据经向格距(度)*10000
unsigned int nYResolution;//数据纬向格距(度)*10000
short nZResolution;//数据高度间隔 (m)(-1:表示间隔不相等)
unsigned int nRadarStationInfoStart;//雷达站信息起始位置(自数据头末尾开始的字节数)
unsigned int nHeightInfoStart;//各层高度数据起始位置(自数据头末尾开始的字节数)
unsigned int nDataInfoStart;//数据起始位置(自数据头0字节开始的字节数)
char Hold2[8];//保留8个字节
}RadarMosaicDataFileHeader;//拼图头文件
#endif

#ifndef RADARSITEINFO
typedef struct TagRADARSITEINFO // 52 Bytes
{
int SiteID; //Site index
char SiteName[20];//Site Name, the number of characters is not more than 20
char SiteType[12];//Site type, whitch indicates data format type <=12 chars
int SiteLon; //Longtitude of the site(Degree*1000)
int SiteLat; //Latitude of the site(Degree*1000)
int SiteHgt; //Height(m) above sea level of the antenner
int ObsRange; //Observation range(km)
}RADARSITEINFO;






另最好有c++类型与c#类型对比表。
...全文
576 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
michaelnami 2010-03-09
  • 打赏
  • 举报
回复
好复杂 还没睡醒 只能帮顶
soaringbird 2010-03-09
  • 打赏
  • 举报
回复
用上pack=4,改了这两个就可以了。
public UInt32 nXResolution;//数据经向格距(度)*10000
public UInt32 nYResolution;//数据纬向格距(度)*10000
xingyuebuyu 2010-03-08
  • 打赏
  • 举报
回复
[StructLayout(LayoutKind.Sequential,Pack=4)]
public unsafe struct TagMosaicDataFileHeader

{
public UInt16 iVersion; //格式版本号 1,2,- 2字节
public fixed byte Hold1[14];//保留14个字节
public fixed byte cSiteName[20];//区域名称/雷达站名 20个字节
public fixed byte strDataType[4];//数据类型 -4 Bytes
public UInt16 TotalRadarStationNum;//组网区域内雷达站数
public UInt16 nYear;//观测开始日期--年
public UInt16 nMonth;
public UInt16 nDay;
public UInt16 nHour;
public UInt16 nMinute;
public int nStartLongitude; //数据开始经度,度×1000
public int nStartLatitude;//数据开始纬度,度×1000
public int nEndLongitude; //数据终止经度,度×1000
public int nEndLatitude;//数据终止纬度,度×1000
public UInt16 nStartHeight;//数据起始高度(m)
public UInt16 nEndHeight;//数据终止高度(m)
public UInt16 nXNumGrids;//经度方向格点数
public UInt16 nYNumGrids;//纬度方向格点数
public UInt16 nZNumGrids;//数据层数

public UInt32 nXResolution;//数据经向格距(度)*10000
public UInt32 nYResolution;//数据纬向格距(度)*10000

public short nZResolution;//数据高度间隔 (m)(-1:表示间隔不相等)
public UInt32 nRadarStationInfoStart;//雷达站信息起始位置(自数据头末尾开始的字节数)
public UInt32 nHeightInfoStart;//各层高度数据起始位置(自数据头末尾开始的字节数)
public UInt32 nDataInfoStart;//数据起始位置(自数据头0字节开始的字节数)
public fixed byte Hold2[8];//保留8个字节
};//拼图头文件

unsigned int是32位的数据,用UInt32 进行代替
soaringbird 2010-03-08
  • 打赏
  • 举报
回复
保持内存布局一致即可
msdnsyh 2010-03-08
  • 打赏
  • 举报
回复
现在的问题是要怎样让 c++与c#的结构体长度相等.
msdnsyh 2010-03-08
  • 打赏
  • 举报
回复
现在的问题是要怎样让
c++与c#的结构体长度相等。解决了就给分了,哈哈。
yinqiuyan 2010-03-08
  • 打赏
  • 举报
回复
看起来你做的项目很难,佩服,帮顶!
fengling2001 2010-03-08
  • 打赏
  • 举报
回复
char chr[255] O StringBuilder
KCA_DIR I int
LPCSTR I string
int I int
LPSTR O StringBuilder
int* O out int
DWORD I int
DWORD* O out int
BOOL I bool
Rc_DBMgr I IntPtr
long* O out long
十八道胡同 2010-03-08
  • 打赏
  • 举报
回复
c++会自动内存对齐,而 c#不会的
msdnsyh 2010-03-08
  • 打赏
  • 举报
回复
这个是我改的,长度是104,原来的那个是112,没郁闷中,怎么让长度一致啊?请教,谢谢大家啊!
[StructLayout(LayoutKind.Sequential,Pack=4)]
public unsafe struct TagMosaicDataFileHeader

{
public UInt16 iVersion; //格式版本号 1,2,- 2字节
public fixed byte Hold1[14];//保留14个字节
public fixed byte cSiteName[20];//区域名称/雷达站名 20个字节
public fixed byte strDataType[4];//数据类型 -4 Bytes
public UInt16 TotalRadarStationNum;//组网区域内雷达站数
public UInt16 nYear;//观测开始日期--年
public UInt16 nMonth;
public UInt16 nDay;
public UInt16 nHour;
public UInt16 nMinute;
public int nStartLongitude; //数据开始经度,度×1000
public int nStartLatitude;//数据开始纬度,度×1000
public int nEndLongitude; //数据终止经度,度×1000
public int nEndLatitude;//数据终止纬度,度×1000
public UInt16 nStartHeight;//数据起始高度(m)
public UInt16 nEndHeight;//数据终止高度(m)
public UInt16 nXNumGrids;//经度方向格点数
public UInt16 nYNumGrids;//纬度方向格点数
public UInt16 nZNumGrids;//数据层数
public UInt16 nXResolution;//数据经向格距(度)*10000
public UInt16 nYResolution;//数据纬向格距(度)*10000
public short nZResolution;//数据高度间隔 (m)(-1:表示间隔不相等)
public UInt32 nRadarStationInfoStart;//雷达站信息起始位置(自数据头末尾开始的字节数)
public UInt32 nHeightInfoStart;//各层高度数据起始位置(自数据头末尾开始的字节数)
public UInt32 nDataInfoStart;//数据起始位置(自数据头0字节开始的字节数)
public fixed byte Hold2[8];//保留8个字节
};//拼图头文件

110,577

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧