how to get a pointer to a stream?

  • Thread starter Thread starter Assido
  • Start date Start date
A

Assido

Hello @all,

can someone tell me how to get a pointer to a stream?
I need to pass the pointeraddress to an API-Functioncall.

Thanks for any help!
 
Hi,

it is more likely that you want to pass the streams content
to the API call. You did not name the API Function but
i guess it expects just a bunch of memory or a pointer
so this might work for you:


//CODE

byte[] byteMemoryFromSream; //will hold stream bytes
MemoryStream ms = new MemoryStream(255); //memory stream with 255 bytes
content, here comes our stream into play
byteMemoryFromSream = new byte[ms.Length]; //reserve bytes of size
ms.lengtht (255)
IntPtr ptrMemoryStreamContent = Marshal.AllocHGlobal((int)ms.Length);
//allocate memory from heap
Marshal.Copy(byteMemoryFromSream, 0, ptrMemoryStreamContent,
(int)ms.Length);
//YourApiCall(ptrMemoryStreamContent); //passing memory pointer to the API
call
Marshal.FreeHGlobal(ptrMemoryStreamContent);//release memory from heap


//CODE END

To make sure this works, use exception handling and parameter checking
for invalid or null types,...

Regards

Kerem

--
 

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

Back
Top