473,836 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3690
>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?
CreateStreamOnH Global

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

"Cartoper" <ca******@gmail .comwrote in message
news:8c******** *************** ***********@d27 g2000prf.google groups.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...@no spam.jun0.c0mwr ote:
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?

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

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

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::FromStre am.
"Cartoper" <ca******@gmail .comwrote in message
news:a5******** *************** ***********@y5g 2000hsf.googleg roups.com...
On Dec 11, 2:41 pm, "Michael Phillips, Jr."
<mphillip...@no spam.jun0.c0mwr ote:
>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?

CreateStreamOn HGlobal

Ok, how do I convert the 'IStream *' to 'System::IO::St ream __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::St ream __gc *'
so I can use it in the .Net world?

You can't convert the unmanaged COM IStream to a managed
System:IO::Stre am.
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::FromStre am.
Or if copying the memory backed by the HGLOBAL is unacceptable, write your
own implementation of System::IO::Str eam 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::Str eam that reads (and writes?) the
memory. It's not a lot of code to write.
Or just use the UnmanagedMemory Stream 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::Str eam that reads (and
writes?) the memory. It's not a lot of code to write.

Or just use the UnmanagedMemory Stream 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_remov e_this_and_nos. ..@mvps.org.nos pamwrote:
Mattias Sjögren wrote:
Or just use the UnmanagedMemory Stream 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******** *************** ***********@a35 g2000prf.google groups.com...
On Dec 13, 12:26 am, "Carl Daniel [VC++ MVP]"
<cpdaniel_remov e_this_and_nos. ..@mvps.org.nos pamwrote:
Mattias Sjögren wrote:
Or just use the UnmanagedMemory Stream 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
52699
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 using streams, datadoc, xmlreader, etc with no success. I need to convert it directly to a string or via a stream, but not in a file. Here's some sample code that gives me the bad format. I'll post the good format below that give me rowsets rather...
7
7129
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 without strtol or s/printf function. Thanks, whatluo.
6
52277
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 StreamObject.Read(myByteArray, 0, myLength) --
3
15331
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 written a conversion? TIA, Matt
7
2371
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 instance). MIDL_INTERFACE("7FD52380-4E07-101B-AE2D-08002B2EC713") IPersistStreamInit : public IPersist { public: virtual HRESULT STDMETHODCALLTYPE IsDirty( void) = 0; virtual HRESULT STDMETHODCALLTYPE Load(/* */ LPSTREAM pStm) =
6
29454
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 "<" & ">" directly.... I have done googling, but all return shareware. I would like to know how to programming...but not using shareware... Thanks all.
3
3162
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 somebody, please, help me out? I am on this for days. My code is as follows:
11
5068
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
9441
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 halts the program. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= WebClient client = new WebClient(); string url="<url of the api>"; Stream data = client.OpenRead(url);
0
9826
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10560
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9389
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6984
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5831
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4466
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.