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

C#调用VC的DLL涉及到结构参数,急啊
这是VC DLL中定义的结构
typedef struct
{
char* strFontName;  
int iFontSize;  
BOOL bFontBold;  
BOOL bFontItaic;  
BOOL bFontUnderline;  
COLORREF colorFont;  
int iAlignStyle;  

}User_FontSet;

typedef struct
{
int iX;  
int iY;  
int iWidth;  
int iHeight;  
int iFrameMode;  
COLORREF FrameColor;  
}User_PartInfo;

typedef struct _User_MoveSet
{
int iActionType;  
int iActionSpeed;  
BOOL bClear;  
int iHoldTime;  
}User_MoveSet;


typedef struct _User_SingleText
{
char *chContent;  
User_PartInfo PartInfo;  
COLORREF BkColor;  
User_FontSet FontInfo;  
User_MoveSet MoveSet;  
}User_SingleText;

调用的方法是:
int User_AddSingleText(int iCardNum,User_SingleText *pSingleText,int iProgramIndex);


我在C#中写了如下代码:
  [StructLayout(LayoutKind.Sequential)]
  public struct User_PartInfo
  {
  [MarshalAs(UnmanagedType.I4)]
  public int iX;
  [MarshalAs(UnmanagedType.I4)]
  public int iY;
  [MarshalAs(UnmanagedType.I4)]
  public int iWidth;
  [MarshalAs(UnmanagedType.I4)]
  public int iHeight;
  [MarshalAs(UnmanagedType.I4)]
  public int iFrameMode;
  [MarshalAs(UnmanagedType.I4)]
  public int FrameColor;

  }
  public struct User_FontSet
  {
  [MarshalAs(UnmanagedType.ByValTStr,SizeConst =30)]
  public string strFontName;
  [MarshalAs(UnmanagedType.I4)]
  public int iFontSize;
  [MarshalAs(UnmanagedType.Bool)]
  public bool bFontBold;
  [MarshalAs(UnmanagedType.Bool)]
  public bool bFontItaic;
  [MarshalAs(UnmanagedType.Bool)]
  public bool bFontUnderline;
  [MarshalAs(UnmanagedType.I4)]
  public int colorFont;
  [MarshalAs(UnmanagedType.I4)]
  public int iAlignStyle;

  }
  public struct User_MoveSet
  {
  [MarshalAs(UnmanagedType.I4)]
  public int iActionType;
  [MarshalAs(UnmanagedType.I4)]
  public int iActionSpeed;
  [MarshalAs(UnmanagedType.Bool)]
  public bool bClear;
  [MarshalAs(UnmanagedType.I4)]
  public int iHoldTime;

  }
  public struct User_SingleText
  {
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
  public string chContent;
  [MarshalAs(UnmanagedType.Struct)]
  public User_PartInfo PartInfo;
  [MarshalAs(UnmanagedType.I4)]
  public int BkColor;
  [MarshalAs(UnmanagedType.Struct)]
  public User_FontSet FontInfo;
  [MarshalAs(UnmanagedType.Struct)]
  public User_MoveSet MoveSet;

  }


  [DllImport("Dll.Dll")]
  public static extern int User_AddSingleText(int iCardNum, User_SingleText 

pSingleText, int iProgramIndex);


但调用此方法时提示出错“