1
我结束了一类读取一个自定义的二进制数据文件,使数据提供给.NET/C#类如何“针” C++/CLI指针
不过几行下来的代码,我开始得到内存访问冲突错误,我相信是由于GC走动内存,类管理
下面是C#调用代码 - 读者混合代码(管理上的旧非托管代码的包装方法)
if (! reader.OpenFile(...))
return ;
foreach(string fieldName in fields)
{
int colIndex = reader.GetColIndex(fieldName);
int colType = reader.GetColType(colIndex); // error is raised here on 2nd iteration
}
for (int r = 0 ; r < reader.NumFields(); r++)
{
foreach(string fieldName in fields)
{
int colIndex = reader.GetColIndex(fieldName);
int colType = reader.GetColType(colIndex); // error is raised here on 2nd iteration
switch (colType)
{
case 0 : // INT
processField(r, fieldName, reader.GetInt(r,colIndex));
break ;
....
}
}
}
....
阅读器有一个旧的非托管类实例引用NCE持有二进制数据在内存中 ,这是一个指针类型,因为托管类无法持有的非托管类型
我看interior_ptr,pin_ptr但他们给出错误c3160不能在管理
类任何解决方法?顺便说一句,这是我很长一段时间的第一个C++程序!
UPDATE: 更新了Q,再上面是调用代码和读卡器混合(管理+旧的非托管代码)
&是参数都是有效的
是C++的读者?上面的代码看起来更像C#而非foreach,而不是每个。 – dkackman 2010-06-09 17:17:55
什么类型是'reader'?它是一种托管类型吗? 'colType'的价值是什么?这是一个有效的价值吗? – 2010-06-09 17:18:01
“foreach”是C#关键字还是使用'boost'库?AFAIK,C++没有'foreach'关键字,这意味着你不是用C++编写的! – 2010-06-09 17:28:14