关于指针数组的封送问题

tdtdtdtdtd123 2011-08-04 05:25:17
我用c#调用C++的dll,碰到指针数组的封送的问题
这是一个dll的调用结构
typedef struct tagPlayFile // 播放文件
{
int fid; // 文件序号(序号小于 0则取全路径)
char fname[100]; // 文件名或全路径名
} PlayFile, *LPPlayFile;
这个c++函数
int IPCAST_FilePlayStart(PlayFile* pFList[], int fCount, ULONG* pTList, int tCount,
int Grade, int CycMode, int CycCount, int CycTime);
这个函数如何在c#中改写
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tdtdtdtdtd123 2011-08-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 skygpan 的回复:]
属性->允许不安全代码?
[/Quote]
不太想用这种方式,似乎不安全啊
tdtdtdtdtd123 2011-08-09
  • 打赏
  • 举报
回复
pFile = new clsIPCase.PlayFile();
pFile.fid = 2 ;
pFile.fname = "gg.mp3";
如何取得pFile对象的IntPtr呢?
sdl2005lyx 2011-08-05
  • 打赏
  • 举报
回复
1、先把C++的结构体在C#中进行映射:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct tagPlayFile // 播放文件
{
int fid; // 文件序号(序号小于 0则取全路径)
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
string fname; // 文件名或全路径名
}

2、正确声明函数:

[DllImport("xx.dll", EntryPoint = "IPCAST_FilePlayStart", CharSet = CharSet.Ansi,CallingConvention =CallingConvention.Cdecl)]
public static extern int IPCAST_FilePlayStart([In,Out]IntPtr[] pFList, int fCount, ref uint pTList, int tCount, int Grade, int CycMode, int CycCount, int CycTime);

剩下的就是你在C#中的调用了。。。。
潘少博 2011-08-05
  • 打赏
  • 举报
回复
属性->允许不安全代码?
tdtdtdtdtd123 2011-08-05
  • 打赏
  • 举报
回复
没人会?

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧