How do you go about "properly" setting up SFML for VS 2013? While a few places have given me a bit of information how to do it, nothing quite seems to work except one thing: SFML MS2012 Extension. However, I'd like to know how to do this from scratch for VS 2013 without the need of the extension.
Here is the current process I am using without the extension:
1) Open new project in VS 2013.
2) Add References to SFML libs(dlls): sfml-audio-2, afml-graphics-2 and sfml-windows-2.
3) Add extended libs via add-existing files: csfml-audio-2, csfml-graphics-2, csfml- windows-2, libsndfile-1 and openal32.
4) Create application.
Between the extension and doing everything myself, the noticeable difference is the GUID in the assembly information, yet if I attempt the previous steps and insert the GUID from the extension project into the new project, my attempt still fails to work even though the projects end up looking exactly the same. On top of which, where does the GUID come from and how do I go about getting it?
Secondary Question: Does XNA have all of the audio/graphic/window handling as SFML does? If so would it be better to switch to XNA than use SFML.Net?
Create a new C# project in Visual Studio 2012/2013/2015. It can be a Console Application or a Windows Forms Application. The only difference is, that a Windwos Forms Application generates a Form wich you can safely remove and the Console Applications shows a Console in the background.
Right-click your project in the Solution Explorer and click on Add Reference…
When the Reference Manager window appears, browse to the folder where you extracted the SFML.net archive and go to the lib folder. Select all the .dll files in the lib folder and Click on ‘OK’ in the Reference Manager to add them to your project.
Once the .dll files appear in the References section of your project, right-click your project again and click on Add > Existing Item… Navigate to the extlibs folder and add all the .dll files there (you may have to select .dll files as file filter in the Open dialog box).
Once these .dll files appear on your Solution Explorer, right-click on them and select Properties (or press Alt-Enter). In the Copy to Output Directory property, set it to Copy if newer.
SFML.net is now set-up for your project. To test it you can run this example code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using SFML;
using SFML.Graphics;
using SFML.Window;
namespace SFML_Test {
static class Program {
static void OnClose(object sender, EventArgs e) {
// Close the window when OnClose event is received
RenderWindow window = (RenderWindow)sender;
window.Close();
}
static void Main() {
// Create the main window
RenderWindow app = new RenderWindow(new VideoMode(800, 600), "SFML Works!");
app.Closed += new EventHandler(OnClose);
Color windowColor = new Color(0, 192, 255);
// Start the game loop
while (app.IsOpen()) {
// Process events
app.DispatchEvents();
// Clear screen
app.Clear(windowColor);
// Update the window
app.Display();
} //End game loop
} //End Main()
} //End Program
}
It should output this:
I have set up my SFML.Net projects in Visual Studio 2013 and 2015 through this tutorial. I used some of the text from it for this answer.
Related
I have made a Windows Forms Project which hosts a WPF User Control (some kind of 3D Viewport), which are basically two "seperate" Projects.
Combining these two in one Main Project did work and i can access the Wpf with my Windows Forms App.
In the next step i wanted to create an "MSIX" App as Visual Studio 2019 suggests. So i inserted a "third" Project Template ( the MSIX project template ) and set up the References like in the official how to Guide. So that was mainly linking my "Main" Windows Forms Program as an Application in the MSIX Template and also setting it as an "Entry Point" for the App.
My WPF Program is referenced in my Main Program so i didnt have to link this in the MSIX Template again.
So far so good. The Debugging also doesnt bring any Errors.
But instead of opening the Main program (which is WinForms) as defined Entry Point, the Debugger opens just the WPF Application ( which is actually only accessible through a ButtonClick Event in the Windows Forms Programm) ....
In the .wapproj file:
<EntryPointProjectUniqueName>..\..\Visu 2.0 Core\Visu 2.0 Core\Visu 2.0 Core.csproj</EntryPointProjectUniqueName>
which is the Folderplace of my imported project (Main WindowsForms program part) which i do want to run..
I read about the property
<EntryPointexe/>
I now have two places where i could get my .exes from: the folder where i originally created the program
or the folder where i "built" the project anew together with the MSIX project specific stuff ( under a new project name)
So i dont really get if setting this could help out. It seems more to be an other reason why my App wont run/show the initial (windows)form.
My attempts to setting the also somehow had an effect on the AppxManifest.xml file located in
..\source\repos\AppTest2\AppTest2\bin\AnyCPU\Debug\AppxManifest.xml
Has anybody an advice why my App Project (even though the entry point) doesnt want to know anything from my 1. Program Part ? ( it is just not run but the second program WPF though)
# Knally.Based on my test, I use Windows Forms Project as Entry Point in MSIX Template, it opens Windows Forms Project and WPF User Control is loaded when the button is clicked. You can check if the steps are consistent with yours. And if there is any problem, please let me know.
Here are my code in .wapproj file:
<EntryPointProjectUniqueName>..\WindowsFormsApp1\WindowsFormsApp1.csproj</EntryPointProjectUniqueName>
The steps:
Create WPF App Project named WpfApp1 and build to WpfApp1.dll.
【
1.Create a new WPF App Project
2.Add a User Control
3.Create control
4.Delete Window1 and App files in Solution Explorer
5.Project > WpfApp1 Properties > Application > Output Type = Class Library
6.Build solution... .dll file is in the bin/Release folder
】
2.Create Windows Forms App named WindowsFormsApp1 and add reference MyControl.dll.
【Right click References in WindowsFormsApp1->select Add Reference…->select Browse ->find and Add WpfApp1.dll->click OK】
The Form1.cs code:
using System;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using WpfApp1;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ElementHost host = new ElementHost();
host.Dock = DockStyle.Bottom;
UserControl1 myControl = new UserControl1();
host.Child = myControl;
this.Controls.Add(host);
}
}
}
3.Create Windows Application Packaging Project named WapProjTemplate1.
【
1.Right click Applications -> click Add Reference…->Select WindowsFormsApp1->click OK
2.Double click Package.appxmanifest->Click Packaging->click Choose Certificate…->click
Create…->enter password->OK
3.modify your Configuration Manager as below:
4.Right click WapProjTemplate1->select Publish->select Create App Packages…->select Release for Architecture on Select and configure packages wizard as below:
The result:
I am facing this problem enter image description herewhen trying to add a new class to my project
Can anyone help me please
If you cannot add class to your project using IDE, as a workaround you can do it manually.
Go to your project's directory (where Program.cs is located)
Create new file named Class1.cs (you can give any name)
Go to Visual Studio and see is new class appeared.
If it didn't click on Show All Files, see your class, right click on it and choose Include in project
But this is obviously not a long term solution. Try repairing your Visual Studio using Visual Studio Installer
I am very confused because I created a new project in Visual Studio 2019. I have tried this three separate times with different projects, and each time it exports as a DLL instead of an EXE. Here are the steps to reproduce this problem:
New project
Console App (.NET Core)
Set details for new project, and hit the "Create" button
Add Microsoft.Win32.Registry NuGet package to project
Add the following code:
using Microsoft.Win32;
using System;
namespace Key_Statistics_Startup_Changer {
class Program {
static void Main(string[] args) {
if (args[0] == "CREATE_STARTUP") {
RegistryKey rkey = Registry.CurrentUser.CreateSubKey(#"Software\Microsoft\Windows\CurrentVersion\Run");
rkey.SetValue("Key Statistics", #"C:\Program Files\Key Statistics\Key Statistics.exe");
}
else if (args[0] == "REMOVE_STARTUP") {
RegistryKey rkey = Registry.CurrentUser.CreateSubKey(#"Software\Microsoft\Windows\CurrentVersion\Run");
rkey.DeleteValue("Key Statistics");
}
}
}
}
Build and run project
When I do this, the program does create or remove the desired registry from startup (what the code is trying to accomplish), when I input arguments through Visual Studio. However, when this project is built, my Key Statistics Startup Changer\bin\Debug folder gives me a sub-directory netcoreapp2.1 with the following files:
Key Statistics Startup Changer.deps.json
Key Statistics Startup Changer.dll
Key Statistics Startup Changer.pdb
Key Statistics Startup Changer.runtimeconfig.dev.json
Key Statistics Startup Changer.runtimeconfig.json
I am positive that I have the right folder where it would export, and every time I re-create the steps (making sure I don't select C# DLL project), this happens.
What's the deal here?
You went wrong when you chose Console App (.NET Core) instead of Console App (.NET Framework) ,
In a nutshell, it's harder getting a .exe from .net core than .net framework.
No worries though, you can simply copy all your code and paste them in a new
Console App (.NET Framework) project.
Right click on the project and go to properties. Choose the Application tab and, on the right side, you have an option called Output Type. You can choose whatever you want; for example, if you want your project to emit a DLL, just choose Class Library.
When you are setting up the Application Folder: Add/Project Output/... on the options to choose, pick "Publish items" instead of "Primary Output".
This will package .exe files instead of .dll, if you do want .dll files, then choose "Primary Output" to the Output Group.
How can I change at runtime the caption in the right-click context menu for the taskbar button for my program? I mean the text circled in red here.
The caption appears to be taken from the assembly title. I need to alter the caption dynamically at runtime from code. I have one EXE which the users "see" as a number of different apps - it reads data files at runtime and then customizes its appearance massively, including the window caption. I need to also customize the caption in this right-click menu. There's no single caption that covers everything. I'm willing to consider P/Invoke calls to the Windows API if necessary.
This is a WinForms .Net 4.5.2 program, screenshot is Windows 7.
I have a solution for you, but not sure it will work for you
I will make some assumptions to drive home my solution
It is a winforms project built using visual studio
You haven't modified your original Program.cs file
All your assembly attributes are in AssembyInfo.cs
Program.cs typically looks like this
using System;
using System.Windows.Forms;
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
One way to deal with it is to build your app as a Class Library sans the Program.cs, let's call it App.dll. Then merge your code from Program.cs and AssemblyInfo.cs (only relevant portions) into a single file and let's call it App.cs. You should auto-generate App.cs either with a separate script or via App.cs itself
Now build App.cs referencing App.dll generating App.exe. This App.exe should work exactly like your current executable.
Once all this is established, you can already see where we are going with this.
Now, when your App.exe start's up and reads the config to make changes, you should auto-generate App.cs with a different AssemblyTitle like below
[assembly: AssemblyTitle("MyAssembly")]
and generate App-Flavor1.exe, and spawn that process and exit out of App.exe
Long time ago but...
You can modify it in the "Registry Editor".
Open the "Registry Editor" (in windows 10, click on START > type reg and you will have it on the search results).
Click on the "Edit" menu > "Find". A dialog box will be opened.
Type the name of the executable file of your program (e.g. "MyAppName.exe") > "Find Next".
Now you should see property which name ends with "FriendlyAppName" and the value is the current caption name. Right click on it and then click on "Modify".
Type your desired caption name in the "Value" textbox. > OK.
If you have several copies of this app in your PC then go over all of them using the "Edit > Find Next" menu item and modify them all.
Be careful not to modify any other values in the Registry Editor, it may harm your PC well being.
Using Visual Studio 2005
I have list of class files, when i try to run the class files, it showing error as
"a project with output type of class library cannot be started directly"
How to run the class file? How to create a dll file.
Am new to visual studio 2005
Need Help?
A Class Library is just that, a library of code, you need to create an application that references the library to try it out.
In the same solution, just add a new project as a Winforms Application and then in the winforms application project add a reference to the class library project.
You should then be able to call the methods in the library from the application code.
To create a DLL File, click on New project, then select Class Library.
Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.
Now, look in your directory: ../debug/release/YOURDLL.dll
There it is! :)
P.S.
DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.
Then, to be able to use this dll file, in your projects code, you call the methods inside the dll file. For example:
If, in your DLL file you have a method like this:
public string somerandommethod()
{
string x = "something";
return x;
}
Then, in your Form1.cs file of your separate project, you would call the code from your dll file like this:
button1_Click(object sender, EventArgs e)
{
MyDllFile dll = new MyDllFile();
MessageBox.Show(dll.somerandommethod());
}
I hope this has helped you
You cannot run projects of type class library. You need to define a startup project that is either a console application, windows application or a web application which would use the class library.
If you are creating a library, look at using something like NUnit to test it. It will load the dll and execute whatever tests you define on it.
You can not run a class file, either you can go to project properties ->Application - > Output type. Here you can specify the application type as console application so your code will run on command prompt.
Also make sure that the project you are trying to run is set as startup project (you can do it by right click on project and select "Set as Startup project".
To create a DLL you need to select New Project -> Class library.