-1

I am using a lib to preview and capture snapshots from capture cards.

The lib: http://www.codeproject.com/Articles/34663/DirectShow-Examples-for-Using-SampleGrabber-for-Gr

It was built for .net 2.0 and everything works perfectly when those classes and controls are called from .net 2.0 or 3.5 projects.

When I add the reference to it from a .net 4.0 project, I am getting a fantastic exception.

Arithmetic operation resulted in an overflow.

when trying to:

GCHandle handle = GCHandle.Alloc(this.savedArray, GCHandleType.Pinned);
int scan0 = (int)handle.AddrOfPinnedObject();

I would happily change my app to .net 2.0 but I need it to be in .net 4.0 to reference some other libs.

I have no idea how to solve this. I have tried to compile those libs in .net 4.0 and succeeded, but when executing that piece of code, same problem. Could it be a problem in .net 4.0?

I am lost. It would be perfect if you could provide some guidance in this matter.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
hpinhal
  • 512
  • 6
  • 22

1 Answers1

3

An int is a 32-bit integer. If you are on a 64 bit machine, addresses aren't 32 bit, but 64 bits.

Use Int64 (long) instead to match the processor's address length:

long scan0 = (long)handle.AddrOfPinnedObject();

Or, even better, call ToInt64:

long scan0 = handle.AddrOfPinnedObject().ToInt64();
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325