mirror of
https://github.com/guilhermewerner/rust-ffi
synced 2025-06-15 21:34:19 +00:00
Add C# Example
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,6 +17,7 @@ Source/Library.h
|
|||||||
|
|
||||||
*.sln
|
*.sln
|
||||||
*.vcxproj
|
*.vcxproj
|
||||||
|
*.csproj
|
||||||
*.filters
|
*.filters
|
||||||
*.user
|
*.user
|
||||||
|
|
||||||
|
37
Examples/CSharp/Program.cs
Normal file
37
Examples/CSharp/Program.cs
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
premake5.lua
47
premake5.lua
@ -95,3 +95,50 @@ project "C"
|
|||||||
runtime "Release"
|
runtime "Release"
|
||||||
buildoptions "/MD"
|
buildoptions "/MD"
|
||||||
optimize "on"
|
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"
|
||||||
|
Reference in New Issue
Block a user