C++结构体:
typedef struct
{ LONG cfHeight; //字符高度
LONG cfWidth; //字符宽度
LONG cfWeight; //字符粗细
LONG cfSpacing; //字符间距
BOOL cfItalic; //斜体
BOOL cfUnderline; //下划线
BOOL cfStrikeOut; //删除线
BOOL bTransparent; //透明
CString str;
COLORREF cfBkColor; //背景色
COLORREF cfTextColor; //前景色
TCHAR cfFaceName 32]; //字体名}OSDPARAM;
C++函数原形:
BOOL WINAPI VCASetVidCapDateTimeOSDParam( OSDPARAM* pOSDParm );
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapDateTimeOSDParam")]
public static extern bool VCASetVidCapDateTimeOSDParam(ref OSDPARAM1 pOSDParm);
当结构体OSDPARAM1 只有一个变量时VCASetVidCapDateTimeOSDParam()能调用成功,C#声明的结构体如下:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct OSDPARAM1
{
public Int32 cfHeight; //字符高度
}
当结构体有2参数却不能成功,报一个C++的错误!!!!!!!!!!
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct OSDPARAM1
{
public Int32 cfHeight; //字符高度
public Int32 cfWidth; //字符宽度
}
真是不明白啊!
不会是我引用的C++ DLL的结构体有问题吧????????????????
来帮帮偶吧
大虾~
typedef struct
{ LONG cfHeight; //字符高度
LONG cfWidth; //字符宽度
LONG cfWeight; //字符粗细
LONG cfSpacing; //字符间距
BOOL cfItalic; //斜体
BOOL cfUnderline; //下划线
BOOL cfStrikeOut; //删除线
BOOL bTransparent; //透明
CString str;
COLORREF cfBkColor; //背景色
COLORREF cfTextColor; //前景色
TCHAR cfFaceName 32]; //字体名}OSDPARAM;
C++函数原形:
BOOL WINAPI VCASetVidCapDateTimeOSDParam( OSDPARAM* pOSDParm );
[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapDateTimeOSDParam")]
public static extern bool VCASetVidCapDateTimeOSDParam(ref OSDPARAM1 pOSDParm);
当结构体OSDPARAM1 只有一个变量时VCASetVidCapDateTimeOSDParam()能调用成功,C#声明的结构体如下:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct OSDPARAM1
{
public Int32 cfHeight; //字符高度
}
当结构体有2参数却不能成功,报一个C++的错误!!!!!!!!!!
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct OSDPARAM1
{
public Int32 cfHeight; //字符高度
public Int32 cfWidth; //字符宽度
}
真是不明白啊!
不会是我引用的C++ DLL的结构体有问题吧????????????????
来帮帮偶吧
大虾~
解决方案 »
- C#判断数据为空
- 水晶报表初级问题:报表只显示字段名称,却没有数据显示!
- 跪求:关于Server.URLEncode的问题
- 要租用空间建立一个小型网站,数据库选什么好?
- WCF 发布问题
- 哪位能找到.net的MSDN文档下载?请告诉我!
- 在WinForm绘图过程中出现了一个奇怪的问题,求解答!
- AccessViolationException 异常
- c#中关于写注册表的一个小问题???
- 又一个WSDK的问题搞不定了,关于QuickStartExample:AsymmetricEncryption,又弹出:“Invalide Security Token”?
- 一个简单的从DataList得到ID再传到CS文件里返回的问题
- C# & Delphi 编码问题?我自己也说不清楚。。。。不过我怀疑是这样的。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
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;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = ??)]
public string str;
public int cfBkColor;
public int cfTextColor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string cfFaceName;
}大体是这样的,我不清楚str的定义是如何的。
public static extern bool VCASetVidCapDateTimeOSDParam(IntPtr pOSDParm);
改的话:
public static extern bool VCASetVidCapDateTimeOSDParam(ref IntPtr pOSDParm); 参考Marshal.StructureToPtr