473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Convert HGlobal into a Stream

I have an image stored in a HGlobal and would like to load it into a
System::Image via the System::Image::FromStream(). How do I convert
the HGlobal into a stream?
Dec 11 '07 #1
8 3661
>I have an image stored in a HGlobal and would like to load it into a
System::Image via the System::Image::FromStream(). How do I convert
the HGlobal into a stream?
CreateStreamOnHGlobal

See MSDN:
http://msdn2.microsoft.com/en-us/library/aa378980.aspx

"Cartoper" <ca******@gmail.comwrote in message
news:8c**********************************@d27g2000 prf.googlegroups.com...
>I have an image stored in a HGlobal and would like to load it into a
System::Image via the System::Image::FromStream(). How do I convert
the HGlobal into a stream?

Dec 11 '07 #2
On Dec 11, 2:41 pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
I have an image stored in a HGlobal and would like to load it into a
System::Image via the System::Image::FromStream(). How do I convert
the HGlobal into a stream?

CreateStreamOnHGlobal
Ok, how do I convert the 'IStream *' to 'System::IO::Stream __gc *' so
I can use it in the .Net world?

Dec 12 '07 #3
Ok, how do I convert the 'IStream *' to 'System::IO::Stream __gc *' so
I can use it in the .Net world?
You can't convert the unmanaged COM IStream to a managed System:IO::Stream.

If you want a Net solution use a MemoryStream.

Marshal the unmanaged memory represented by your HGlobal to a managed buffer
of type byte.
Create a MemoryStream object from this buffer and pass the MemoryStream
object to Image::FromStream.
"Cartoper" <ca******@gmail.comwrote in message
news:a5**********************************@y5g2000h sf.googlegroups.com...
On Dec 11, 2:41 pm, "Michael Phillips, Jr."
<mphillip...@nospam.jun0.c0mwrote:
>I have an image stored in a HGlobal and would like to load it into a
System::Image via the System::Image::FromStream(). How do I convert
the HGlobal into a stream?

CreateStreamOnHGlobal

Ok, how do I convert the 'IStream *' to 'System::IO::Stream __gc *' so
I can use it in the .Net world?

Dec 13 '07 #4
Michael Phillips, Jr. wrote:
>Ok, how do I convert the 'IStream *' to 'System::IO::Stream __gc *'
so I can use it in the .Net world?

You can't convert the unmanaged COM IStream to a managed
System:IO::Stream.
If you want a Net solution use a MemoryStream.

Marshal the unmanaged memory represented by your HGlobal to a managed
buffer of type byte.
Create a MemoryStream object from this buffer and pass the
MemoryStream object to Image::FromStream.
Or if copying the memory backed by the HGLOBAL is unacceptable, write your
own implementation of System::IO::Stream that reads (and writes?) the
memory. It's not a lot of code to write.

-cd
Dec 13 '07 #5
>Or if copying the memory backed by the HGLOBAL is unacceptable, write your
>own implementation of System::IO::Stream that reads (and writes?) the
memory. It's not a lot of code to write.
Or just use the UnmanagedMemoryStream class (assuming .NET 2.0 or
later).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 13 '07 #6
Mattias Sjögren wrote:
>Or if copying the memory backed by the HGLOBAL is unacceptable,
write your own implementation of System::IO::Stream that reads (and
writes?) the memory. It's not a lot of code to write.

Or just use the UnmanagedMemoryStream class (assuming .NET 2.0 or
later).
Even better! (I knew it was in there somewhere - just couldn't remember the
name!)

-cd
Dec 13 '07 #7
On Dec 13, 12:26 am, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
Mattias Sjögren wrote:
Or just use the UnmanagedMemoryStream class (assuming .NET 2.0 or
later).

Even better! (I knew it was in there somewhere - just couldn't remember the
name!)
But I am using .Net 1.1 :(
Dec 13 '07 #8
But I am using .Net 1.1 :(

The MemoryStream class is available with Net 1.1 to Net 3.5.

Marshaling the unmanaged HGlobal memory to a managed byte array is not
difficult.

"Cartoper" <ca******@gmail.comwrote in message
news:cb**********************************@a35g2000 prf.googlegroups.com...
On Dec 13, 12:26 am, "Carl Daniel [VC++ MVP]"
<cpdaniel_remove_this_and_nos...@mvps.org.nospamwr ote:
Mattias Sjögren wrote:
Or just use the UnmanagedMemoryStream class (assuming .NET 2.0 or
later).

Even better! (I knew it was in there somewhere - just couldn't remember
the
name!)
But I am using .Net 1.1 :(
Dec 13 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: jk | last post by:
I'm having trouble converting a datatable into xml, with resonse.write to aspx. I'm basically converting vb code that saved a recordset into a stream into c#, but the format is wrong. I've tried...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
6
by: Hardy Wang | last post by:
Hi all: The Stream object from WebRequest.GetResponseStream() is non-seekable. How can I convert this stream to a byte array? For ordinary Stream (seekable), I can use...
3
by: MJB | last post by:
I'm getting an IStream back from function xmlHttp.responsestream. I would like to convert this to a System.IO.Stream in order to work with it in my application. Has anyone encountered this and...
7
by: Charles Law | last post by:
Can anyone convert the following C++ interface definition to VB.NET? I have had a go, but I cannot make the Load function work and the IsDirty function gives an error (Object not set to an...
6
by: PenguinPig | last post by:
Dear All Experts I would like to know how to convert a HTML into Image using C#. Or allow me contains HTML code (parsed) in Image? I also tried this way but it just display the character "<" &...
3
by: shapper | last post by:
Hello, Could someone tell me how to convert a XML file into another XML file using a XSL file with a parameter? I created the code to do it, and it seems ok, but it is not working. Could...
11
by: Sudzzz | last post by:
Hi, I'm trying to convert a string something like this "{201,23,240,56,23,45,34,23}" into an array in C++ Please help. Thanks, Sudzzz
4
by: Brad | last post by:
I am trying to convert an XML Stream received from a web api call into a DataSet to use in the rest of the app. The issue I am running into is that it will not convert the stream to a dataset and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.