Link How to get IntPtr from byte [] in C #
I am trying to read data that IntPtr refers to byte [] and then back to another IntPtr. The pointer refers to the image taken from the scanner device, so I also made the assumption that the capture of this information should be placed in an array of bytes.
I'm also not sure if the Marshal.SizeOf () method will return the size of the data that IntPtr refers to, or the size of the pointer itself.
My problem is that I get the error "Type" System.Byte [] 'cannot be marshaled as an unmanaged structure, without a significant size or offset it can be calculated "
IntPtr bmpptr = Twain.GlobalLock (hImage); try { byte[] _imageTemp = new byte[Marshal.SizeOf(bmpptr)]; Marshal.Copy(bmpptr, _imageTemp, 0, Marshal.SizeOf(bmpptr)); IntPtr unmanagedPointer = Marshal.AllocHGlobal( Marshal.SizeOf(_imageTemp)); try { Marshal.Copy(_imageTemp, 0, unmanagedPointer, Marshal.SizeOf(_imageTemp)); Gdip.SaveDIBAs( string.Format("{0}\\{1}.{2}", CaptureFolder, "Test", "jpg"), unmanagedPointer, false); } finally { Marshal.FreeHGlobal(unmanagedPointer); } } catch (Exception e) { Scanner.control.Test = e.Message; }
c # interop marshalling intptr
Scruffy the janitor
source share