473,396 Members | 1,789 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,396 software developers and data experts.

Write a Manifest Resource to File (VB, .net 2.0)

I must be totally missing something.

I am trying to use DirectX to play an AVI file that is stored as a
Manifest Resource. Apperently the Video class only takes a string path
as a parameter, so I wanted to write the avi to a file from the
manifest. I thought I would just be able to read it in as a Stream and
then write it out to a FileStream but this does not seem to be the
case.

To complicate things, I just found out about the ResourceManager, but
I'm not quite sure how to use that in an abstracted sort of way (the
My.Resource stuff that is generated is very specific and I want it to
be generalized). This is what I have so far:

Function GetVideo(ByVal resourceIdentifier As String, ByVal videoName
As String) As Video

Dim fileLocation As String
Dim videoFileInfo As FileInfo
Dim aviFile As Video

fileLocation = Application.StartupPath + "\" + videoName
videoFileInfo = New FileInfo(fileLocation)

If Not videoFileInfo.Exists Then
Dim resourceStream As Stream
resourceStream = System.Reflection.Assembly _
.GetExecutingAssembly.GetManifestResourceStream(re sourceIdentifier
+ "." + videoName)

Dim videoFileStream As New FileStream(fileLocation,
FileMode.Create)

'SO HOW DO I WRITE???

videoFileStream.Close()
End If

aviFile = New Video(fileLocation)

Return aviFile

End Function

Obviously I need some logic to catch any exceptions, but could someone
tell me what the easy way to do this is?

Cheers!
Dinsdale

Mar 1 '07 #1
3 3380
>I am trying to use DirectX to play an AVI file that is stored as a
Manifest Resource. Apperently the Video class only takes a string path
as a parameter, so I wanted to write the avi to a file from the
manifest. I thought I would just be able to read it in as a Stream and
then write it out to a FileStream but this does not seem to be the
case.
Can't you just ship it as a separate file?

If not, you simply have to call resourceStream.Read in a loop, reading
a chunk of the stream at a time, and write it to the file with
videoFileStream.Write.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 1 '07 #2
On Mar 1, 4:18 pm, Mattias Sjögren <mattias.dont.want.s...@mvps.org>
wrote:
I am trying to use DirectX to play an AVI file that is stored as a
Manifest Resource. Apperently the Video class only takes a string path
as a parameter, so I wanted to write the avi to a file from the
manifest. I thought I would just be able to read it in as a Stream and
then write it out to a FileStream but this does not seem to be the
case.

Can't you just ship it as a separate file?

If not, you simply have to call resourceStream.Read in a loop, reading
a chunk of the stream at a time, and write it to the file with
videoFileStream.Write.

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/|http://www.dotnetinterop.com
Please reply only to the newsgroup.
Thanks Mattias. I'm curious though; I've seen someone write a byte
array into a file in one statement. Is it not possible to read a
stream into a file in one statement? (disclaimer, I'm a C# programmer
using VB.net so please excuse any syntax errors)

'Read a byte array into a file
Dim byteArray() as Byte = ...

Dim myfile as New FileStream("C:\File.avi", FileMode.Create)

myFile.Write(byteArray, 0, byteArray.Length)

myFile.Close()

Is this not possible with a stream? Can anyone explain why this is?

Cheers
Dinsdale

Mar 2 '07 #3
>Thanks Mattias. I'm curious though; I've seen someone write a byte
>array into a file in one statement. Is it not possible to read a
stream into a file in one statement? (disclaimer, I'm a C# programmer
using VB.net so please excuse any syntax errors)

'Read a byte array into a file
Dim byteArray() as Byte = ...

Dim myfile as New FileStream("C:\File.avi", FileMode.Create)

myFile.Write(byteArray, 0, byteArray.Length)

myFile.Close()
>Is this not possible with a stream? Can anyone explain why this is?
Well you can make a single call to Stream.Read and request all of the
data to be read at once (pass in Stream.Length). It will probably work
for most Stream classes (if you stay away from network IO). The
problem with that is that the Stream contract lets implementations
return less than the amount of data requested, and the Length property
may not be supported if the stream isn't seekable. The stream
abstraction is meant to support arbitrary data streams, including
infinite ones.

You can also do sort of what you want with the BinaryReader class.
Like this

Dim br As New BinaryReader(yourStream)
Dim byteArray() as Byte = br.ReadBytes(yourStream.Length)

But again this assumes that the Length property will not throw. And it
doesn't scale well to large amounts of data.

If you know the source and size of your stream you can surely get away
with the above. But when working with arbitrary streams from unknown
sources you have to be a bit more careful.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 2 '07 #4

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

Similar topics

3
by: Werner Merkl | last post by:
Hi, Python is really great, for small to big programs. For my colleagues and some circumstances I sometimes need to "compile" a script using py2exe. Cause I use Windows, I like to use the...
2
by: Alexander Wehrli | last post by:
Hi, I embedded some configuration XML-File into my assembly. Everything goes fine if I want to read these Properties. But if I want to change a property, the runtime says me that this stream is...
5
by: anthony.duerr | last post by:
I have encountered a problem (most certainly a .NET bug), that, for the life of me, I cannot figure out how to work around. Using Visual Studio 2003, with enabled XP Visual Styles. There are...
3
by: Jonathan Payne | last post by:
Hi, I am interested in adding a manifest file to the resources for a MFC application. When I create an AppWizard MFC app with a manifest file it adds the following lines to the .rc file: ...
11
by: RossettoeCioccolato | last post by:
Is there any way to coax the VC8 linker into generating an application manifest with a trust level section suitable for an administrative application? Or do I have to add this manually each time...
1
by: Steve Teeples | last post by:
Can an application manifest document be added to a C# application? If so, can it be done from within the IDE of Visual Studio 2005? I want to customize my application's security level...
1
by: Bern McCarty | last post by:
I know how with VC8 you embed your linker generated manifest into an exe with a resource ID of #1 and into a dll with resource ID #2. But what do you do with the linker generated manifest for a...
0
xarzu
by: xarzu | last post by:
Getting a C# program with a manifest file to run in the debugger ---------------------------------------------------------------- How do I declare a manifest file in the Visual Studio IDE for C#...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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,...

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.