Write Resource file for .net project using the command line - c#

I need to create a resource file for a .net project (by hand) and compile it using the ResGen.exe tool provided by the .NET framework. I can't find any documentation for this. I need to write the resource file by hand because I'm in a situation where I don't want to download/buy extra tools (like VS) to generate this resource file, and also I feel more productive through the command-line (helps me understand how things really work).
So I need to write a resource file by hand to store an ICON in the executable and use it from within my program. I would also like to use this icon to represent my executable in Windows Explorer.
Any references would be great!

Visual C# Express Edition will do what you want for free. If nothing else you can download that, create the resource file and then use that as a subject for your admirable curiosity about 'how it really works'. This may also save you some time in manual experimentation to get it right the first time around.

These 2 links in conjunction provide information on using that tool to create and embed an icon file, it seems specific to C#. Of course i'm guessing at your full intention, let me know if this points you in the proper direction.
http://www.xtremedotnettalk.com/showthread.php?t=75449
specifically there is a post which states;
I think you should first create a *.resources-File from the Icon with the tool named "Resgen.exe"...
resgen App.ico App.ico.resources
the next step would be compiling...
csc /t:winexe /out:Keygen.exe /res:App.ico.resources /r:Crypto.dll /win32icon:App.ico Keygen.cs AssemblyInfo.cs
I'm sure you were here already.
http://msdn.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx

You should check this link:
http://msdn.microsoft.com/en-us/library/ekyft91f.aspx
It explains what formatter is used and gives some code samples to generate one from code. You could then write a small wrapper app that you can call from the command line. No downloads needed!

Related

How can I incorporate an AddReg section into a config file for a Compact Framework app?

I'm trying to update a registry value in a Windows CE / Compact Framework app.
I can do what I want in .NET 4.5, but .NET 3.5 is missing some of the pieces to do it that way (specifically RegistryView and OpenBaseKey; the curious can peruse all the gory details here).
Another possibility is to ship a *.reg file with the app and invoke it via ShellExecuteEx(), but that seems a bit Rubegoldbergish to me.
Yet another possibility is to use P/Invoke, but that seems like modified Hobbesianism (nasty and brutish, but not short (short would be good in this case)).
SO...I did finally find something that seems like an almost eurekaphoric option. According to Andy Wigly in his book "Microsoft .NET Compact Framework" (printed 1879 or so), you can add or manipulate registry values via a configuration file. This config file seems to be embedded in a/the cab when the app is deployed on the device. Quoting from the book:
"*AddReg *
Defines the name of the section of the configuration file for adding entries to the registry; ..." (p. 211)
-and:
"*Description of the AddReg Section*
The *AddReg* sections are optional sections of the configuration file. These sections are defined by the *AddReg* key under the *DefaultInstall* section of the configuration file. Each section defines the registry keys, and values are added to the registry when your application is installed. For more information, see the device's SDK (p. 213)
But what configuration file is here being so cavalierly bandied about? I can't locate where he backs up and gives fundamental info about it.
Okay, I can try to locate "the device's SDK" (they are Motorola 3090/3190 devices onto which this app is installed) but am hoping that somebody knows just which configuration file he's talking about, and what the needed entry looks like.
We have a separate install app for this app, and I searched it for "AddReg" and "DefaultInstall", but to no avail.
I'm thinking that the file probably has to have a specific name for the cab to know what it is and run it (*.config?) and that the entry might be something like:
[DefaultInstall]
[AddReg]
"GuestOnly"="00000001"
...but I don't really know, that's just a guess. Does anybody know what this entry is supposed to look like? It sure would be a much simpler way of changing the registry val than P/Invoke and the like.
It's not the *.vcproj file, is it? (the setup app is written in C++; the app itself is C#).
UPDATE
It turns out I may be barking up the wrong tree with this attempt to update the "GuestOnly" setting.
UPDATE 2
At any rate, it can't hurt (and may help) to updated that value; so, I looked through our C++ install app, but it contains no .inf files, nor any reference to such, so I guess the best or only real way to do this is by adding the registry updating code to the app itself. I call it from the main form's Load() event.
Many ways to skin that cat, but I typically have that kind of thing right in the CAB setup. I use a program that slaps a UI on it, but all it is doing is creating a configuration file (.inf) and passes it to CAB Wizard (https://msdn.microsoft.com/en-us/library/aa448616.aspx).
The file info, including AddReg is here (https://msdn.microsoft.com/en-us/library/aa448654.aspx).

visual c# button opens file without specifying drive

I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.

Game Launcher and Updater for Windows

So, I want to create a simple launcher for a game that I'm making for Windows. I want to write it on Visual Studio so it can do the following:
Launch the game wherever the .exe file is. (either via registry key or by the user selecting the destination)
Auto-install all the needed dependences for the game if they are missing or provide a link to install them.
Verify intergrity of the files.
Auto download the latest patch or take the user to the patch download site (optional).
In addition of these, I need some help on the following:
Assuming that I can set it up to download the patch, how can I deliver it? I'm not sure that the program can download files from SkyDrive can it?
How do I set it up as a 32-bit program? I have a 64-bit system here.
Is it possible to write a Metro version of the launcher using the same code?
Please note that the game will be in a "installable format". I'll be using Install Creator for this.
Thanks for any help in advance.
I've written a similar software before for a game, that did almost the same things as you described. Given that you have not shown any code, I'll answer the 3 questions in a general, basic way.
1.) Depends on what you mean by patch. An installer that supposed to replace or extend existing files, delete old files, deploy new ones? In that case it's up to the installer to manage it. If a patch simply downloads a file and puts it in the right place you can download it from either Skydrive (DriveOne) or any other place. Check out the API and the examples here.
2.) I'm not sure I understand this question, but I think you just want to compile your binary to 32bit in visual studio and that's it.
3.) Yes.

anksvn checkin file

I am using the most recent version of anksvn for a visual studio 2008 project file. I now
want to check this code into anksvn, but I am having a problem.
The situtation is, I checked in the most current version of code into anksvn. That is fine.
However I have another version of this code that I did not check out from subversion initially. This other copy of the code was for a 'demo' only. However now this code needs to become the production code. Thus I am trying to determine how to check this code into anksvn.
What I know I can do is to 'remove' the most curent code folder that is in anksvn. I could then place this project folder into that location. since the origianl 'demo' code also includes the current production code.
However I am trying to see if there is a better method to accomplish this goal. Could I possibly use the branch/switch option?
Is the demo code checked out of Subversion at all? I know you didn't check it out, but was it checked out? If it was, you could commit this code back into Subversion, then update your working directory.
It his code has nothing to do with Subversion, you will have to take a more complex route: You will have to copy the changes manually to your code.
Since you're using Windows, you should take a look at Beyond Compare, This is commercial code, but you can download a limited time demo for free -- more than enough time to handle your situation. I use Beyond Compare all the time to compare two different directories or Java jar files or zip archives, etc. It not only can quickly show you the differences, but makes it each to copy those differences from one to the other.
I have no relationship with Scooter software, the makers of Beyond Compare except as a customer.

Is it possible to generate complex tones in C#?

I need to create a sound containing tones of many different frequencies. Is there any way to do this in C#?
The only tone generating methods I've seen so far involve console.beep, which works, but only for pure tones (single frequencies).
The Audiere library makes this extremely easy to do. Here's a nearly complete C# program to generate the DTMF tone for the "1" button:
AudioDevice device = new AudioDevice();
OutputStream tone1a = device.CreateTone(697); // part A of DTMF for "1" button
OutputStream tone1b = device.CreateTone(1209); // part B
tone1a.Volume = 0.25f;
tone1b.Volume = 0.25f;
tone1a.Play();
tone1b.Play();
Thread.Sleep(2000);
// when tone1a stops, you can easily tell that the tone was indeed DTMF
tone1a.Stop();
To use Audiere in C#, the easiest way to get up and running is to use Harald Fielker's C# binding (which he claims works on Mono and VS; I can confirm it works in the both full version of VS2005 and using the separate Express 2008 versions of C# and VC++). You'll need to download the Win32 Audiere DLL, lib, and header (which are all in the same zip) and you'll need to build the C# binding from source using both VC++ and C#.
One of the nice benefits of using Audiere is that the calls are non-blocking. You don't have to wait for tone1a to stop playing before you start tone1b, which is clearly a necessity for playing complex tones. I am not aware of any hard upper limits on how many simultaneous output streams you can use, so it's probably whatever your hardware/OS supports. By the way, Audiere can also play certain audio files (MP3, WAV, AIFF, MOD, S3M, XM, IT by itself; Ogg Vorbis, Flac, Speex with external libraries), not just pure generated tones.
One possible downside is that there is a slightly audible "click" as you start or stop an individual tone; it's not noticeable if you add one tone to an already playing tone. The easiest workaround I've found for that is to slowly ramp the tone's volume up or down when you're turning the tone on or off, respectively. You might have to play around with the ramp speed to get it to sound "just right".
Note that Audiere is LGPL-licensed, and the binding has no license attached to it. You'll have to consult your legal team or try to get a hold of Harald if you want to use his binding in a commercial product; or you could just make your own binding and avoid the hassle.
#Tom: Since there is no specific license attached to Harald's library, I'm not sure what implications would come of hosting it; however, I believe I can at least give you fine detail on exactly how my libaudieresharpglue project is set up.
Using Visual C++ Express 2008, open up bindings/csharp/libaudieresharpglue/vc8.0/libaudieresharpglue.sln. VC++ will automatically convert the solution to a VS9 solution.
In another folder, you should have the Audiere package from Sourceforge. Under your VC++ project properties, go to Configuration Properties > C/C++ > General, and make sure you have path/to/audiere-1.9.4-win32/include in your "Additional Include Directories." Then, in that same window, go to Linker > General and make sure you have /path/to/audiere-1.9.4-win32/lib in your "Additional Library Directories." Then, you should be able to build the project (preferably in Release mode) and this output libaudieresharpglue.dll in your vc8.0/Release folder.
Next, open up Visual C# Express 2008. Open up bindings\csharp\test\vc8.0\AudiereCSharpTest.sln and let it convert the solution. The project should build fine, but then you will get an error when you run it. That's fine; in your csharp/test/vc8.0/bin/Release folder, you need to add both libaudieresharpglue.dll from the VC++ solution and audiere.dll from the package from Sourceforge.
Now, you should be able to build and run AudiereCSharpTest. Note that by default, #define stream_test is not commented out at the top of AudiereTest.cs, and that will reference a file that is not on your hard drive. You can simply comment out that #define and uncomment noise_test or square_test.
That should cover it; if I missed any details, hopefully they are small enough to get by on your own :)
You can always try DirectSound...
I have been looking at NAudio with the view to create a program that emulates feedback whilst playing a backing track. There is a blog post about generating sine waves at specific frequencies, I suspect that this could be adapted to do what you are looking for.
Yes it is possible.
Here is a link to a tutorial on this. but of course this also uses Console.Beep
The MSDN documentation doesn't make it clear if Console.Beep is asynchronous or not. If it is, you can probably fire off as many calls as you need in quick succession and nobody will be the wiser. You'd want to use the version that takes a frequency and a duration, of course.
Essentially, you have to implement your own software synthesizer or find a 3rd party library. See: http://en.wikipedia.org/wiki/Demo_(computer_programming)#Music

Categories