How can I get IntPtr pointer from object

Ezi picture Ezi · May 3, 2011 · Viewed 14.1k times · Source

I'm working on a finger-print device, the manufacture (Upek) gave me a c++ BSAPI.dll so I need to use wrappers to get this to work in .net.

I'm able to work with it all from in-memory, I could grab and match the finger prints.

Now I'm stuck trying to get the data out to a file and then loading it back in to memory and get the IntPtr.

Here there's a c++ sample on how to export and import from a file. but I don't know how to read it.

Any help is appreciated Thanks all


This is what I have and works great: enter image description here

Now I need two things 1. Take that bufBIR save it to a database. 2. Take the data I saved and pass it in to the abs_verify.

How can this be done?

Answer

Tim Matthews picture Tim Matthews · Jan 17, 2012

I don't know what the body of the question means but to answer the title :

How can I get an IntPtr from object?

This is intentionally made to require a little bit of work, with good reason. The garbage collector can often re locate objects within memory so can and only be done by 'pinning' it. To do this you must create a GCHandle with GCHandleType 'Pinned' and then you can call GCHandle.AddrOfPinnedObject. This will throw an Exception if it is not pinned.

Also you should note that GCHandle.ToIntPtr returns the value of the handle not the address of the object. This is basically used to have a single integral value that can be passed easily around before reconstructing the GCHandle.