help with byte arrays and pointers

P

Patrick

I've search for hours on this problem and cannot find a solution :(

Heres the bit of code:
IntPtr pointer = getFrameDll(FrameNumber);

The pointer points to a byte[] array that represents a bitmap.

I do not know the length of the array and Marshal.SizeOf() returns 4 bytes
(32 bit integer)

for the size of the pointer.

Could someone please teach me how to get byte arrays from memory using
pointers?

Gratefully,

Patrick
 
T

Truong Hong Thi

Heres the bit of code:
IntPtr pointer = getFrameDll(FrameNumber);
Could someone please teach me how to get byte >arrays from memory using
pointers?
I think it is imposible. The function should also outputs the array
length.

Thi
 
P

Patrick

I was afraid of that. It's all a learning lesson :)
BTW, trying to convert this line from Delphi to C#
function getFrameDll(frame: integer): PByteArray; cdecl; external
'vidframe.dll' name '?getFrame@@YAPAEH@Z';

Thanks for the quick reply. (about 4 minutes)
 
T

Truong Hong Thi

I just had a look at System.Drawing namespace documentation and see
that the Bitmap constructor also accepts IntPtr and additional params.
Hope it works!
 
P

Patrick

I just tried it. "A generic error occurred in GDI+". Does csharp have
something similar to a PByteArray ? Or is there a way to say the equivelant:
public static extern byte[]* foo()?
 
W

Willy Denoyette [MVP]

Patrick said:
I just tried it. "A generic error occurred in GDI+". Does csharp have
something similar to a PByteArray ? Or is there a way to say the
equivelant: public static extern byte[]* foo()?

Truong Hong Thi said:
Did you try methods like System.Drawing.Image.FromHBitmap?

Yes, it has it's the IntPtr retuned , but if you don't know the length of
the byte[] pointed to by the returned poiner, how are you going to handle
the array contents?
Isn't it possible that the frame has a fixed lentgh? How do you manage this
in Delphi?

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top