有关C#比较高深的问题,高手请回答

fhqypm_126 2008-12-11 09:41:29
最近用C#做了一个视频编辑的例子。可是出现了尝试读取受保护的内存。说明其它内存已坏。不知是什么原因,还请高手帮忙。代码如下:

.dll中是如下说的:
int TC_SegmentToFile(OUT char *_pcSaveFile, long _lBeginPos, long _lEndPos, char *_pcSourceFile);

 

功能:把视频片断保存在指定的文件中

参数:_pcSaveFile 保存文件

_lBeginPos 视频片断在原文件中的起始位置

_lEndPos 视频片断在原文件中的结束位置

_pcSourceFile 视频片断所在的文件

返值:0 操作成功

-1 编辑器正在进行其它操作

<-1 失败
我是如下用的:
[DllImport("PlaySdkM4.dll")]
public static extern int TC_SegmentToFile(out string savefile, long _lBeginPos, long _lEndPos, string sourcefile);

TC_SegmentToFile(out savefile, begin, end, sourcefile);
其中:savefile="C:\123.sdv" begin=1 end=9 sourcefile="C:\故乡的云.sdv"
可是总是说尝试读取受保护的内存。说明其它内存已坏。
...全文
277 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
wartim 2008-12-13
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 fhqypm_126 的回复:]
int TC_SegmentToFile([in,out] char[] _pcSaveFile, int _lBeginPos, int _lEndPos, [in,out] char[] _pcSourceFile);

这个也不行呀,本身就不正确。提示in是关键字。呵呵!
[/Quote]

sorry,我记错了,[in,out] char[] 是我以前在delphi里引入一个c++的驱动库时的delphi写法...
fhqypm_126 2008-12-13
  • 打赏
  • 举报
回复
谢谢楼上的朋友们,我的这个问题还是没有解决。可能小弟是菜鸟的问题。不知错哪了。呵呵
wartim 2008-12-12
  • 打赏
  • 举报
回复

int TC_SegmentToFile([in,out] char[] _pcSaveFile, int _lBeginPos, int _lEndPos, [in,out] char[] _pcSourceFile);

试试,这种转换是挺麻烦的,char* =>[in,out] char[]是可行的
再不行可能要用那种Marshal Lp什么的了,忘了
xiangweixing 2008-12-12
  • 打赏
  • 举报
回复
或者 savefile 在执行程序之前你的文件已经存在,记得删除它!
xiangweixing 2008-12-12
  • 打赏
  • 举报
回复
[DllImport("PlaySdkM4.dll")]
public static extern int TC_SegmentToFile(out string savefile, long _lBeginPos, long _lEndPos, string sourcefile);


--不给 savefile 初始值看看
fhqypm_126 2008-12-12
  • 打赏
  • 举报
回复
对不起,各位。我来晚了。今天我按照各位的意见试了一下,还是不行。我先是把long改为int ,不行,后来又改为int32,还是不行。之后我又将string改为stringbulider还是不行。它们都报出尝试读取受保护的内存。这通常是指其它内存已坏。说实话,以上的各种意思小弟先前也试了多次。有位兄弟说:为什么不用C++,我们公司用C#做网络中控的软件。它比较简单。呵呵,还是谢谢各位,如果还有其它的好主意,请贴出来。放心即使不能解决问题,分照给。再次谢谢各位。
ccimage 2008-12-12
  • 打赏
  • 举报
回复
我想可能是Ansi和Unicode的问题,在[DllImport("PlaySdkM4.dll")] 加上, CharSet = CharSet.xxx。具体的可以翻翻MSDN
极地_雪狼 2008-12-12
  • 打赏
  • 举报
回复
学习一下。
bbbbbb888888 2008-12-12
  • 打赏
  • 举报
回复
友情up
ccimage 2008-12-12
  • 打赏
  • 举报
回复
这不是海康的吗,一般是类型错误
fhqypm_126 2008-12-12
  • 打赏
  • 举报
回复
int TC_SegmentToFile([in,out] char[] _pcSaveFile, int _lBeginPos, int _lEndPos, [in,out] char[] _pcSourceFile);

这个也不行呀,本身就不正确。提示in是关键字。呵呵!
fhqypm_126 2008-12-12
  • 打赏
  • 举报
回复
楼上的说不给savefile赋值。可是如何将文件保存呢?它不只是字符串,更是一个文件的路径。
niitnanfeng 2008-12-11
  • 打赏
  • 举报
回复
标记下。
zhyuanshan 2008-12-11
  • 打赏
  • 举报
回复
楼主应该把原函数的声明写出来
wanghui0380 2008-12-11
  • 打赏
  • 举报
回复
请用StringBuilder做Char*的参数类型
CNBeing 2008-12-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gogogo 的回复:]
[DllImport("PlaySdkM4.dll")]
public static extern int TC_SegmentToFile(out string savefile, int _lBeginPos, int _lEndPos, string sourcefile);
[/Quote]

正解 ,看一下p/v调用
long->int32
gogogo 2008-12-11
  • 打赏
  • 举报
回复
第一个参数内容如果在函数里被改变,改成如下
[DllImport("PlaySdkM4.dll")] 
public static extern int TC_SegmentToFile(StringBuilder savefile, int _lBeginPos, int _lEndPos, string sourcefile);
如果不被改变,如下
[DllImport("PlaySdkM4.dll")] 
public static extern int TC_SegmentToFile(string savefile, int _lBeginPos, int _lEndPos, string sourcefile);
gogogo 2008-12-11
  • 打赏
  • 举报
回复
[DllImport("PlaySdkM4.dll")]
public static extern int TC_SegmentToFile(out string savefile, int _lBeginPos, int _lEndPos, string sourcefile);
birdlonger 2008-12-11
  • 打赏
  • 举报
回复
帮顶,标记!
八爪鱼-杭州 2008-12-11
  • 打赏
  • 举报
回复
.net里,long是64位;c++里是32位.
加载更多回复(1)

111,130

社区成员

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

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

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