Created
September 17, 2024 23:30
-
-
Save jbevain/4a4dd6189686cb53738251f3a6e2c5a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if CS | |
using System.Runtime.InteropServices; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Managed"); | |
var r = Compute(12, 12); | |
Console.WriteLine($"Result: {r}"); | |
Console.WriteLine("Native"); | |
r = ComputeCompiled(12, 12); | |
Console.WriteLine($"Result: {r}"); | |
} | |
[DllImport("ComputeCompiled.dll")] | |
static extern int ComputeCompiled(int a, int b); | |
#elif CPP | |
// cl /LD /Fe:ComputeCompiled.dll /Fd:ComputeCompiled.pdb /Zi /ZH:SHA_256 /D"CPP" /TpProgram.cs | |
extern "C" | |
{ | |
static int Compute(int,int); | |
__declspec(dllexport) int ComputeCompiled(int a, int b) | |
{ | |
return Compute(a, b); | |
} | |
#endif | |
static int Compute(int a, int b) | |
{ | |
int c = a + b; | |
int d = b + c; | |
int e = d * c; | |
return e * 12; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment