473,671 Members | 2,209 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 resourceIdentif ier As String, ByVal videoName
As String) As Video

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

fileLocation = Application.Sta rtupPath + "\" + videoName
videoFileInfo = New FileInfo(fileLo cation)

If Not videoFileInfo.E xists Then
Dim resourceStream As Stream
resourceStream = System.Reflecti on.Assembly _
.GetExecutingAs sembly.GetManif estResourceStre am(resourceIden tifier
+ "." + videoName)

Dim videoFileStream As New FileStream(file Location,
FileMode.Create )

'SO HOW DO I WRITE???

videoFileStream .Close()
End If

aviFile = New Video(fileLocat ion)

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 3402
>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.w ant.s...@mvps.o rg>
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.ne t/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(by teArray, 0, byteArray.Lengt h)

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(b yteArray, 0, byteArray.Lengt h)

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(yo urStream)
Dim byteArray() as Byte = br.ReadBytes(yo urStream.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
5712
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 (Windows) ability, to add some version infos, comments, etc to the exe file. If I use explorer to check, these properties are visible and correct.
2
5686
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 not writable. How can I write to a ManifestResourceStream? Is this impossible? Regards Alexander
5
3232
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 two possible scenarios here, the first one works properly, while the 2nd one doesn't. Scenario 1 ----------
3
3231
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: #ifdef _UNICODE IDR_MANIFEST RT_MANIFEST "res\\TestManifest4.manifest"
11
11193
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 that I rebuild? Regards, George.
1
8071
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 ("Administrator level") and believe it has to be done from within this manifest file that is to be linked into the program. -- ----------- Thanks,
1
1574
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 mixed .netmodule? Do you need to embed the it into the .netmodule? If so, with what ID? Or do you merge the .netmodule linker generated manifest into the manifest that you embed into the "assembly manifest containing" file? I have a 2-file...
0
1514
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# so that I can debug the resulting code? I have been able to add the manifest file, to the exe after I have built the program. But then, when I try to debug my C# code, the program crashes at the point where a function call is made that is used by...
1
3138
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 their paired "foreign" resx for that language only and installs those resource files in a subdirectory somewhere. I'm trying to create a setup project in visual studio 2008. Ive got my Application Folder set up with my executable. Im now...
0
8914
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8820
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
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7433
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
6223
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
5695
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
4224
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1809
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.