I am wrapping up a class which reading a custom binary data file and makes the data available to a .net/c# class
However a couple of lines down the code, i start getting the memory access violation error which i believe is due to the GC moving memory around, the class is managed
Here's the calling code in C# - reader is mixed code ( managed wrapper methods on old unmanaged code )
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 ;
....
}
}
}
....
Reader has an old unmanaged class instance reference which holds the binary data in memory AND It's a pointer type since a managed class cannot hold an unmanaged type
i've looked at interior_ptr, pin_ptr but they give an error c3160 cannot be in a managed class
Any workaround ? BTW, this is my 1st C++ program in a very long time !
UPDATE : updated the Q, again the above is the calling code and reader is mixed ( managed + old unmanaged code )
& yes the arguments are all valid