Click here to Skip to main content
13,503,790 members
Rate this:
Please Sign up or sign in to vote.
I've just started working with C#, so I don't have much knowledge.

I'm creating a NFO viewer for information files I make.

The idea is as following:
- A custom skin (so no default windows border) and own buttons on it;
- A richtextbox that converts and shows the .nfo file, autoscrolling and looping;
- Music on application start, button to pause the music (sound off);
- A picture as button to a website;
- Custom Icon;
- I would like to use it as a standalone executable, which runs directly and doesn't have to look for the files it needs (the music file and nfo, dll's? etc.)
For this you should use the resources functionality somehow.

The situation at this point:
I now have an application that runs, custom skin/button, looping music (.it file),
looped autoscrolling text, users can't interact with the box: I don't want them to select etc, NO custom icon. The (.NFO) text and .it music are loaded from a default location (C:\Test\xx.nfo etc.).
It's made using Visual Studio 2010. I set it for x86, as x64 didn't even work in debug mode on my laptop. I use Windows 7 Ultimate x64.
I guess my application won't work on XP because I use/refer to .NET 4, but I want it to run at least on the W7 variants.

Problems at this time:
1) It seems I'm one of the few that are able to run this application.
It succeeded on W7 64 bits .NET 4.0, W7 32 bits .NET?, W8 64 bits .NET 4.5.
I'm trying to find the cause of the error or not being able to run at all.
When I export the files and try to run them on other Pc's, nothing happens or I get an error that .NET 4 isn't on the Pc. But when I install .NET 4, it keeps silent like the rest.
Can anyone support me with this? If you need the project, sourcecode, any files, just let me know!
2) I want to merge the files my application needs in the project itself.
I've read a lot about using Resources, but couldn't get it to work at all.
Most of the time it's because there's no referrence for different things in the code, which you have when you miss the 'using xxxx' that's needed.
If anyone has experience with using resources and calling them within the project, help me out.

If some people want to reserve some time to help me out, instead of different people with 1 idea... Then I can build on the ideas from 1, that knows what has been tried already and how my application works.
Hope to get some help, waiting for responses and thanks for those who try! :)
Posted 6-Dec-12 2:05am
Updated 7-Dec-12 11:54am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

.NET 4 will work on XP (provided it is patched to SP3 - it should be in any case).

The simplest way to do this (and hopefully fix your problem) is to create a Setup and Deployment project for you application, and use that to install you app on the new machine - it knows what version of .NET you need, and will automatically install it if needed. It will also add and register any DLL files you are using, and you can include your data files if you need to.

I am guessing (and given the lack of info you have provided, that's about all I can do at this stage) that you have used DLL files that are not present on the new machines, and a setup program should cure that for you.
DarkTyranno 6-Dec-12 10:46am
The problem is, even if I install .NET 4 manually and apply all Windows updates for it, it still won't run... My laptop is the only thing that seems to be able to run it...
And a setup... I don't want to put those things on the client pc's. Even if I have to, I don't want to include all those dll's and .NET 4 in all my small apps every time (I have more versions which all require that of course). I want a standalone executable that just runs immediately and does its job.
OriginalGriff 6-Dec-12 10:52am
You can't do that, if you use .NET 4 and any external DLLs - you have to provide the framework in which they work.

If you want to provide standalone apps that need no installation, then you need to look at developing native applications, not .NET
Which means you can't use C#...
DarkTyranno 6-Dec-12 11:08am
I don't really get how it works.
I have imported a dll file for .NET 4 which came with the music player, but it had .NET 1.1 and 2.0 too. But I tried to change to those today, it got me a lot of errors.. :/
I also can't just add the installer file for .NET 4 with my exe somehow?
OriginalGriff 6-Dec-12 11:22am
Not really - it's a huge download (or can be depending on what version the target machine starts with - if it starts with no .NET then you need the full file, if it has 3.5 already, then you need a much smaller one).
If the music player DLL is built for .NET 4, then it needs a .NET 4 application and framework.
DarkTyranno 6-Dec-12 11:27am
I have different dll's that came with the music player, it's build for all .NET variants and also for other scripting languages. I'm wondering if that can cause the problem I have, that I'm not able to switch from .NET dll... if I do, the music player options will be marked as unknown etc. Maybe I have to build my apps from scratch, if it can be converted to an older .NET version. This should be the troublemaker of my apps not running on other machines I think. I made such great progress, till I found out I can't run it on any other computer... -.-
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

use the setup deployment module (installshield) or simply use clickonce!

for the resources:
Method #1:
add your file to your project. on your file, open properties, and set "buildaction" to "content" and "copy to output directory" to "do not copy"
Add a "resources file" (.resx) and add your files to it.

in your code :
file => picture.png
resources file => Resource_Manager.resx

var pict = Resource_Manager.picture; // return a bitmap in my case

Method #2:
add your file to your project. on your file, open properties, and set "buildaction" to "embedded resource" and "copy to output directory" to "copy if newer"

in your code:
string path;
// if the file is at the root of your project, the path will be : var path = "mynamespace.document.docx"
// if it is in a directory named "resources_directory", the path will be : var path = "mynamespace.resources_directory.document.docx"
using (var stream = assembly.GetManifestResourceStream("path"))
     // do whatever you want with it

in case one, files will be in the dll, and in case 2, files will stand next to the dlls.

hope it helps.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

For Resources access in your C# project, you can open the project properties, select "Resources" on the left.

The first time, the editor will allow to add a resource file by clicking on a link in this editor page (this file will be named "Resources.resx" and will be in the "Properties" subfolder).
Then you will have an editor in which you can add files, strings, images, ...

To access one of those resources in your program, you just have to reference it by something like this :
Image myImageInResource = Properties.Resources.MyImage;
string myStringInResource = Properties.Resources.MyString1;

The full name of a resource in this file will be :
usually, NamespaceOfYourProject is used by default everywhere in your code, and you can ommit it.

After Discussion and your specific problem of using resource with the IrrKlang library
I successfully tried this code:
// First of All create the Sound Engine from IrrKlang library
IrrKlang.ISoundEngine engine = new IrrKlang.ISoundEngine();
// Create a sound source from a file in resource with a name and file extension
IrrKlang.ISoundSource source = engine.AddSoundSourceFromMemory(Properties.Resources.test, "test.mp3");
// Play the sound using the source object reference
// Wait 5s
// Stop the Sound
// Restart the Sound using its name
// Wait 5s
// Stop the Sound

In this short example, you can see 2 ways to start the sound.
But you must provide a name with its original file extension (in my case ".mp3")
I tried without it, and no sound (nor error) was played.
I think it is a limitation of this IrrKlang library, you might report this as a bug or a possible amelioration to do. I personnaly think it will be nice if the engine report an error when it did not recognise the sound source.
The play2D method always returns an ISound object if playing a sound OR NOT.
DarkTyranno 6-Dec-12 10:58am
Okay, this is something I need to figure out (tried something like this before, but couldn't get it to work)
How can I acces an .it file, which I have to add as 'other'?
It's music, but no default music extension...
I can't use image Musictrack = ... .nameoffile, as it can't draw that file, but I can't replace image with whatever I want. What do I need to use when I want to access that file for instance?
Pascal-78 6-Dec-12 15:42pm
In case of "other", the resource should be available as a Stream like an opened file.
DarkTyranno 6-Dec-12 16:26pm
Still one big questionmark for me...
I tried StreamMode myStreamInResource = Properties.Resources.Xaser_Aeolus;
Where the error was:
Error 1 Cannot implicitly convert type 'byte[]' to 'IrrKlang.StreamMode'

this means StreamMode belongs to my music player and I still can't use my song from the resources, now what?
I've never used open files or stream or anything related to resources, so can you try to code it correctly for me?
Pascal-78 7-Dec-12 4:43am
I looked in the IrrKlang API.NET.
I think you use the ISoundEngine to play sounds.
using this object, you can create a ISoundSource with the method AddSoundSourceFromMemory and then use it in the play2D method of the ISoundSource.

IrrKlang.ISoundEngine engine = new IrrKlang.ISoundEngine();
IrrKlang.ISoundSource source = engine.AddSoundSourceFromMemory(Properties.Resources.Xaser_Aeolus,"Xaser_Aeolus");
engine.play2D(source, false, false, true);

If it didn't work, you can try create a Sound Source from a MemoryStream :
engine.AddSoundSourceFromIOStream(new MemoryStream(Properties.Resources.Xaser_Aeolus), "Xaser_Aeolus")
DarkTyranno 7-Dec-12 5:56am
MemoryStream can't be found, and in the first case, if I create the engine, add the source, all is okay.
When I try to put the source in the play2D, then it marks play2D with error:

Error 2 'IrrKlang.ISoundEngine' does not contain a definition for 'play2D' and no extension method 'play2D' accepting a first argument of type 'IrrKlang.ISoundEngine' could be found (are you missing a using directive or an assembly reference?)

It almost seems to work, but I'm still not there yet.
Default path (string) works, but when I try to add the resource in the engine, either way play2D doesn't support it.
Pascal-78 7-Dec-12 10:23am
I think you put the engine as the first argument of play2D, you should put the source (the object returned by the AddSoundSource....)

The MemoryStream object is in namespace System.IO (System.IO.MemoryStream)
DarkTyranno 7-Dec-12 10:46am
oh no, I used source as the first argument.

IrrKlang.ISoundSource source = engine.AddSoundSourceFromMemory(Properties.Resources.Xaser_Aeolus, "Xaser_Aeolus");
engine.play2D(source, false, false, true);
engine.Play2D("C:\\Test\\", true);
The play2D that tries to get the source gives the error for play2D I mentioned before, the last line works as it is now, but means I have to load the file from a location. I want to build it in the project. Any id?
Pascal-78 7-Dec-12 11:05am
I'm only reading the IrrKlang documentation on Internet (
May be you can try with the name used in AddSoundSourceFromMemory ("Xaser_Aeolus").
or check if you have the last IrrKlang library.
If I have time, I might download the IrrKlang library and do some test.
DarkTyranno 7-Dec-12 11:57am
Thanks, that would help me a lot. I have to go dinner and work now, try more tomorrow.
Pascal-78 7-Dec-12 17:12pm
OK, I made some test and here are my results :
the name in the AddSoundSourceFromMemory must contains the file extension (I tried with "test.mp3")
Then I was able to play sound using directly this name or the source:

IrrKlang.ISoundEngine engine = new IrrKlang.ISoundEngine();
IrrKlang.ISoundSource source = engine.AddSoundSourceFromMemory(Properties.Resources.test, "test.mp3");

And of course, I do not have any "test.mp3" file.
DarkTyranno 7-Dec-12 17:21pm
What do I have to place for Resources.'test'?
I have small options and I chose the track from resource without extension.
Does it really read the last argument (the string file?)
I can fill it with whatever I want, no errors, but no sound as well...
Pascal-78 7-Dec-12 17:37pm
As I wrote in the updated solution, the IrrKlang library must have a file extension in the name. In your case, it must be ".it".
You create the SoundSource using the AddSoundSourceFromMemory with the resource and a name with this extension (for example: "") and then you can use that name in the play2D method (without any path). The engine will not access a file of this name but the sound source you have create with that name.
DarkTyranno 7-Dec-12 17:48pm
I saw I could use the option 'include in project' from the resource folder, but it didn't make any difference. Maybe you're right, I go ask the admin of irrKlang about using it as a resource, maybe they can help me out. Thanks for the efforts, if there are no other options, I have to deliver the music with the executable.
Pascal-78 7-Dec-12 18:04pm
Have you tried this ?
IrrKlang.ISoundEngine engine = new IrrKlang.ISoundEngine();
IrrKlang.ISoundSource source = engine.AddSoundSourceFromMemory(Properties.Resources.Xaser_Aeolus,"");
DarkTyranno 22-Dec-12 17:02pm
I got some answers, but still have to try them out somehow.
I got this:

"Try loading the resource into a memory array. Then you can easily play it using AddSoundSourceFromMemory(). If you are able to IOStream from your resource, you could also use AddSoundSourceFromIOStream, which might be even easier."

"he string you need to give to play2D is usually a filename, but if you add your sound using a custom sound source, you can use the name of the sound source you used.
About how to get the IOStream from your resource: That's up to you."

I don't want to play from memory, this will generate 100's of lines of code, which I have to create using some software to make code from music files.. -.-
I'm interested in the IOStream, but I didn't have the chance to get any simple thing working from resource, so don't know the format. Still trying out when I have the time.
DarkTyranno 7-Dec-12 18:08pm
I've tried something like it, to directly call the track from source with the name and looping to true, now I tried your suggestion too, both didn't work, no sound...
It's getting very late, I'll try the irrKlang community soon then. I'll keep you posted!
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

It took a long time, as those irrklang community people don't help out fast..
I got it working after a while myself, just code only doesn't work, you need to copy lib files, headers, some dll's and refer to them, use 'Using ...' and then the working code.
All steps and the code are updated in the article of my project :D
Creating a NFO Viewer in C# as a beginner
In the meantime I've changed from modplayer, as irrKlang didn't work with many tracks, so now I use 'BASS' from
I'll update all of this in my article as well when I'm ready!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180417.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100