I have an application that uses an external C(?) Dll and it seems like
after I make a specific call to that dll the application will crash at a
random call to the dll in the future. It sometimes crashes the next call
after said call, while sometimes it doesn't crash for 5 minutes; but it
always crashes.
As long as I don't call tira_get_captured_data it doesn't crash so I am
assuming that is the cause. I get a System.ExecutionEngineException error
in System.Windows.Forms.dll or mscorlib.dll and it does not give me a line
number so I am stuck. The call that seems to be the beginning of the end is
[DllImport("Tira2.dll")] public static extern int tira_get_captured_data(ref
IntPtr data, ref int size); I had to make a few conversions, its original
def is
extern "C" __stdcall int tira_get_captured_data ( const unsigned char**
data, int* size )
Is something wrong with the conversion I made?
Thanks in advance
Nat - 30 Jan 2004 04:08 GMT
http://support.microsoft.com/?kbid=327106
http://support.microsoft.com/?kbid=330900
seems that your .NET interop code is not correct somehow.
Nat
> I have an application that uses an external C(?) Dll and it seems like
> after I make a specific call to that dll the application will crash at a
[quoted text clipped - 15 lines]
>
> Thanks in advance
Nat - 30 Jan 2004 04:19 GMT
What might be the case is that your C++ code still has the reference to .NET
object but that object doesn't have a strong reference anywhere in .NET
code. However, .NET GC has no idea that the unmanaged code still access it.
So GC does clean it up. Or if not, it might move the object around. Both of
the cases can cause the weird exception, I think. You can try to pin the
object during the call
GCHandle x = GCHandle.Alloc(data);
tira_get_captured_data(data,size);
x.Free();
Hope it helps.
Nat
> I have an application that uses an external C(?) Dll and it seems like
> after I make a specific call to that dll the application will crash at a
[quoted text clipped - 15 lines]
>
> Thanks in advance
Nat - 30 Jan 2004 04:27 GMT
Sorry... it should be
GCHandle x = GCHandle.Alloc(data, GCHandleType.Pinned);
tira_get_captured_data((IntPtr(x),size);
x.Free();
> What might be the case is that your C++ code still has the reference to .NET
> object but that object doesn't have a strong reference anywhere in .NET
[quoted text clipped - 32 lines]
> >
> > Thanks in advance