Click here to Skip to main content
15,892,804 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
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
Updated 7-Dec-12 11:54am
v2

.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.
 
Share this answer
 
Comments
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... -.-
Hi,
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

C#
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:
C#
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.
 
Share this answer
 
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 :
C#
Image myImageInResource = Properties.Resources.MyImage;
string myStringInResource = Properties.Resources.MyString1;
...


The full name of a resource in this file will be :
NamespaceOfYourProject.Properties.Resources.ResourceName
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:
C#
// 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
engine.Play2D(source,false,false,false);
// Wait 5s
System.Threading.Thread.Sleep(5000);
// Stop the Sound
engine.StopAllSounds();
// Restart the Sound using its name
engine.Play2D("test.mp3");
// Wait 5s
System.Threading.Thread.Sleep(5000);
// Stop the Sound
engine.StopAllSounds();

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.
 
Share this answer
 
v2
Comments
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);
engine.RemoveSoundSource("Xaser_Aeolus");

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.
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 http://www.un4seen.com/
I'll update all of this in my article as well when I'm ready!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900