当前位置:编程学习 > C#/ASP.NET >>

请教:关于C结构体转成C#的结构体?

大家好,我在C#中解析C语言的结构体数据时,出现前半部分可以转换,不知哪位高手可以指教一下,万分感谢!!
c语言结构体如下:

typedef struct _TC_SPML2_HEAD_S_
{
    short           sub_head                   ; /* message sub header                          */      
    short           msg_leng                   ; /* message length                              */
}TC_SPML2_HEAD_S                               ; /* End of "typedef struct _TC_SPML2_HEAD_S_"   */
                                
typedef struct _TC_L21_COIL_SET_SPMPC_S_
{
    TC_L2SPM_HEAD_S msg_head                   ; /* Message header                              */
    int             tc_code                    ; /* tc code =                                   */
    char            ent_coil_no[COIL_NO_LEN]   ; /* Cold coil No                                */
    char            steel_grade[20]            ;
    short           ok_flag                    ;
    short           dummy_mark                 ;
    short           thickness                  ;
    short           width                      ;
    short           length                     ;
    short           weight                     ;
    char            galvanizing_mode[2]        ;
    short           coating_wgt_top            ;
    short           coating_wgt_bot            ;
    short           elongation_std             ;
    short           elongation_min             ;
    short           elongation_max             ;
    short           spm_mode                   ;
    short           tl_mode                    ;
    char            passivation_mode[2]        ;
    short           weld_posi1                 ;
    short           weld_posi2                 ;
    short           weld_posi3                 ;
    char            sharp                      ;
    char            reserve[3]                 ;
    short           roughness                  ;
    char            final_use[4]               ;
    short           reserve1                    ;    
}TC_L21_COIL_SET_SPMPC_S                        ;                 
如何转换为C#语言的结构体???

我没有分了,可以将免费提供我上传的资源!!! --------------------编程问答--------------------
    public struct TC_SPML2_HEAD_S
    {
        public short sub_head ; /* message sub header */  
        public short msg_leng ; /* message length */
    };


    public struct TC_L21_COIL_SET_SPMPC_S
    {
        //TC_L2SPM_HEAD_S msg_head ; /* Message header */
        public int tc_code; /* tc code = */
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100 )] /* Cold coil No */
        public string ent_coil_no;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
        public string steel_grade;
        public short ok_flag;
        public short dummy_mark;
        public short thickness;
        public short width;
        public short length;
        public short weight;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)] /* Cold coil No */
        public string galvanizing_mode;
        public short coating_wgt_top;
        public short coating_wgt_bot;
        public short elongation_std;
        public short elongation_min;
        public short elongation_max;
        public short spm_mode;
        public short tl_mode;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)] /* Cold coil No */
        public string passivation_mode;
        public short weld_posi1;
        public short weld_posi2;
        public short weld_posi3;
        public char sharp;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)] /* Cold coil No */
        public string reserve;
        public short roughness;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 4)] /* Cold coil No */
        public string final_use;
        public short reserve1;
    } ;
--------------------编程问答--------------------
引用 1 楼 akirya 的回复:
C# code
    public struct TC_SPML2_HEAD_S
    {
        public short sub_head ; /* message sub header */  
        public short msg_leng ; /* message length */
    };


    public struct TC_L21_COIL……

c# struct 来表示c++ 的struct注意要加 [StructLayout....
其他的要保证,C# 的数据内存布局与c++ 一致即可
--------------------编程问答-------------------- 用com接口把c中的结构体封装成一个接口 
IData
{
BOOL GetInt(int*)
BOOL SetInt(int)
BOOL GETBSTR(BSTR*)
BOOL SETBSTR(BSTR)
}

这样用起来方便多了 --------------------编程问答-------------------- 一楼答得不错,3楼能否讲得具体点?
补充:.NET技术 ,  VC.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,