typedef struct
{ LONG cfHeight; //字符高度
LONG cfWidth; //字符宽度
LONG cfWeight; //字符粗细
LONG cfSpacing; //字符间距
BOOL cfItalic; //斜体
BOOL cfUnderline; //下划线
BOOL cfStrikeOut; //删除线
BOOL bTransparent; //透明
COLORREF cfBkColor; //背景色
COLORREF cfTextColor; //前景色
TCHAR cfFaceName[32]; //字体名}OSDPARAM;//设置视频捕获文本叠加
BOOL WINAPI VCASetVidCapTextOSD( DWORD dwCard, BOOL bEnableOSD, TCHAR* tcText, POINT& ptTopLeft, OSDPARAM* pOSDParm );
//设置视频捕获时间、日期叠加,在VCASetVidCapDateTimeOSDPARAM()函数设置后调用有效
BOOL WINAPI VCASetVidCapDateTimeOSD( DWORD dwCard, BOOL bEnableOSD, POINT& ptTopLeft);
//设置视频捕获字幕叠加
BOOL WINAPI VCASetVidCapDateTimeOSDParam( OSDPARAM* pOSDParm );
我想要转成 c#的声明 public struct OSDPARAM
{
public int cfHeight; //字符高度
public int cfWidth; //字符宽度
public int cfWeight; //字符粗细
public int cfSpacing; //字符间距
public bool cfItalic; //斜体
public bool cfUnderline; //下划线
public bool cfStrikeOut; //删除线
public bool bTransparent;//透明
public int cfBkColor; //背景色
public int cfTextColor; //前景色
public Byte[] cfFaceName;//字体名
}//设置视频捕获文本叠加
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapTextOSD")]
public static extern bool VCASetVidCapTextOSD(Int32 dwCard, bool bEnableOSD, StringBuilder tcText, Point ptTopLeft, OSDPARAM pOSDParm);
//设置视频捕获时间、日期叠加,在VCASetVidCapDateTimeOSDPARAM()函数设置后调用有效
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapDateTimeOSD")]
public static extern bool VCASetVidCapDateTimeOSD(Int32 dwCard, bool bEnableOSD, ref OSDPARAM pOSDParm);
//设置视频捕获字幕叠加
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapDateTimeOSDParam")]
public static extern bool VCASetVidCapDateTimeOSDParam(ref OSDPARAM pOSDParm);
我的声明有问题,请指正!
C/C++ 中的 COLORREF 是个结构体, 你怎么用 int 类型与它对应?
仔细查看一个COLORREF 的结构, 然后在C#中同样地声明一个相应的结构体才行。其它的我没看,楼下的看看吧。
乱说!COLORREF本身就是一个DWORD。是个宏定义,不是结构体。
//设置视频捕获文本叠加
BOOL WINAPI VCASetVidCapTextOSD( DWORD dwCard, BOOL bEnableOSD, TCHAR* tcText, POINT& ptTopLeft, OSDPARAM* pOSDParm );
//设置视频捕获时间、日期叠加,在VCASetVidCapDateTimeOSDPARAM()函数设置后调用有效
BOOL WINAPI VCASetVidCapDateTimeOSD( DWORD dwCard, BOOL bEnableOSD, POINT& ptTopLeft);
//设置视频捕获字幕叠加
BOOL WINAPI VCASetVidCapDateTimeOSDParam( OSDPARAM* pOSDParm );//设置视频捕获文本叠加
[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode )]
[return: MarshalAs ( UnmanagedType.Bool )]
public static extern bool VCASetVidCapTextOSD(Int32 dwCard, bool bEnableOSD, string tcText, ref Point ptTopLeft, ref OSDPARAM pOSDParm);
//设置视频捕获时间、日期叠加,在VCASetVidCapDateTimeOSDPARAM()函数设置后调用有效
[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode )]
[return: MarshalAs ( UnmanagedType.Bool )]
public static extern bool VCASetVidCapDateTimeOSD(Int32 dwCard, bool bEnableOSD, ref Point pOSDParm);
//设置视频捕获字幕叠加
[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs ( UnmanagedType.Bool )]
public static extern bool VCASetVidCapDateTimeOSDParam(ref OSDPARAM pOSDParm);
BOOL 应该是int
COLORREF 应该是int
TCHAR 有在unicode和非unicode时不一样。char或WCHAR
COLORREF cfTextColor; //前景色要转为color吧!。。不大明白楼下继续参考
另外,TCHAR类型需要明确是Ansi还是Unicode,下面是按Unicode来写的:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OSDPARAM
{
public int cfHeight; //字符高度
public int cfWidth; //字符宽度
public int cfWeight; //字符粗细
public int cfSpacing; //字符间距
public bool cfItalic; //斜体
public bool cfUnderline; //下划线
public bool cfStrikeOut; //删除线
public bool bTransparent;//透明
public uint cfBkColor; //背景色
public uint cfTextColor; //前景色
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string cfFaceName;//字体名
};[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode )]
public static extern bool VCASetVidCapTextOSD(UInt32 dwCard, bool bEnableOSD, string tcText, ref Point ptTopLeft, ref OSDPARAM pOSDParm);[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode )]
public static extern bool VCASetVidCapDateTimeOSD(UInt32 dwCard, bool bEnableOSD, ref Point ptTopLeft);[DllImport("Sa7134Capture.dll", CharSet = CharSet.Unicode)]
public static extern bool VCASetVidCapDateTimeOSDParam(ref OSDPARAM pOSDParm);