diff --git a/.gitignore b/.gitignore index 6b95918..437f89d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ Source/Library.h *.sln *.vcxproj +*.csproj *.filters *.user diff --git a/Examples/CSharp/Program.cs b/Examples/CSharp/Program.cs new file mode 100644 index 0000000..96488ec --- /dev/null +++ b/Examples/CSharp/Program.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.InteropServices; + +namespace CSharp +{ + class Program + { + #if WINDOWS_PLATFORM + const string Library = "Library"; + #else + const string Library = "libLibrary"; + #endif + + [DllImport(Library)] + static extern float Add(float Num1, float Num2); + + [DllImport(Library)] + static extern float Divide(float Num1, float Num2); + + [DllImport(Library)] + static extern float Multiply(float Num1, float Num2); + + [DllImport(Library)] + static extern float Subtract(float Num1, float Num2); + + static void Main(string[] args) + { + int num1 = 1; + int num2 = 2; + + Console.WriteLine("Added: " + Add(num1, num2)); + Console.WriteLine("Subtracted: " + Subtract(num1, num2)); + Console.WriteLine("Multiplied: " + Multiply(num1, num2)); + Console.WriteLine("Divided: " + Divide(num1, num2)); + } + } +} diff --git a/premake5.lua b/premake5.lua index 997e7d1..09dcb66 100644 --- a/premake5.lua +++ b/premake5.lua @@ -95,3 +95,50 @@ project "C" runtime "Release" buildoptions "/MD" optimize "on" + +project "CSharp" + location "Examples/CSharp" + kind "ConsoleApp" + language "C#" + + targetdir ("Binaries/" .. outputDir) + objdir ("Intermediate/") + + files + { + "Examples/%{prj.name}/**.cs", + } + + includedirs + { + "Source" + } + + libdirs + { + "Binaries/%{cfg.buildcfg}" + } + + filter "system:windows" + staticruntime "On" + systemversion "latest" + + defines + { + "WINDOWS_PLATFORM" + } + + links + { + "Library.dll.lib" + } + + filter { "system:windows", "configurations:debug" } + runtime "Debug" + buildoptions "/MDd" + symbols "on" + + filter { "system:windows", "configurations:release" } + runtime "Release" + buildoptions "/MD" + optimize "on"