日期:2014-05-18  浏览次数:20851 次

C#中如何将结构体传入动态链接库中
有一段 VC++ 的结构体,并且封装到了LEDShow.DLL中,
//调用 外部函数
在VC++中的调用方式
DLL_API int __stdcall User_AddSingleText(int CardNum,User_SingleText *pSingleText,int iProgramIndex);
C/C++ code
typedef struct    _User_FontSet        //字体设置
{
    char*        strFontName;        //字体的名称
    int            iFontSize;            //字体的大小
    BOOL        bFontBold;            //字体是否加粗
    BOOL        bFontItaic;            //字体是否是斜体
    BOOL        bFontUnderline;        //字体是否带下划线
    COLORREF    colorFont;            //字体的颜色
    int            iAlignStyle;        //对齐方式
                                    //0- 左对齐 
                                    //1-居中 
                                    //2-右对齐
    int         iVAlignerStyle;        //上下对齐方式
                                    //0-顶对齐
                                    //1-上下居中
                                    //2-底对齐
    int         iRowSpace;            //行间距
}User_FontSet;

typedef struct    _User_PartInfo        //区域设置
{
    int            iX;                    //窗口的起点X
    int            iY;                    //窗口的起点Y
    int            iWidth;                //窗体的宽度
    int            iHeight;            //窗体的高度
    int            iFrameMode;            //边框的样式
    COLORREF    FrameColor;            //边框颜色
}User_PartInfo;

typedef struct _User_MoveSet
{
    int            iActionType;        //节目变换方式
    int            iActionSpeed;        //节目的播放速度    
    BOOL        bClear;                //是否需要清除背景
    int            iHoldTime;            //在屏幕上停留的时间
    int         iClearSpeed;        //清除显示屏的速度
    int            iClearActionType;    //节目清除的变换方式
    int         iFrameTime;
}User_MoveSet;


如何将上述 结构体 和调用方法 转换成 c#代码 
在线等

------解决方案--------------------
C# code
extern static int User_AddSingleText(int CardNum,ref User_SingleText pSingleText,int iProgramIndex);


        struct    User_FontSet        //字体设置
{
    IntPtr       strFontName;        //字体的名称
    int            iFontSize;            //字体的大小
    bool bFontBold;            //字体是否加粗
    bool bFontItaic;            //字体是否是斜体
    bool bFontUnderline;        //字体是否带下划线
    int    colorFont;            //字体的颜色
    int            iAlignStyle;        //对齐方式
                                    //0- 左对齐 
                                    //1-居中 
                                    //2-右对齐
    int         iVAlignerStyle;        //上下对齐方式
                                    //0-顶对齐
                                    //1-上下居中
                                    //2-底对齐
    int         iRowSpace;            //行间距
}

         struct    User_PartInfo        //区域设置
{
    int            iX;                    //窗口的起点X
    int            iY;                    //窗口的起点Y
    int            iWidth;                //窗体的宽度
    int            iHeight;            //窗体的高度
    int            iFrameMode;            //边框的样式
    int    FrameColor;            //边框颜色
}

 struct User_MoveSet
{
    int            iActionType;        //节目变换方式
    int            iActionSpeed;        //节目的播放速度    
    bool        bClear;                //是否需要清除背景
    int            iHoldTime;            //在屏幕上停留的时间
    int         iClearSpeed;        //清除显示屏的速度
    int            iClearActionType;    //节目清除的变换方式
    int         iFrameTime;
}

------解决方案--------------------
C# code
C#中调用Windows API时的数据类型对应关系                    
   
BOOL=System.Int32                    BOOLEAN=System.Int32                    BYTE=System.UInt16
CHAR=System.Int16                    COLORREF=System.UInt32                    DWORD=System.UInt32
DWORD32=System.UInt32                DWORD64=System.UInt64                    FLOAT=System.Float
HACCEL=System.IntPtr                HANDLE=Syst