Used modern approach for C#/C++ interop

This commit is contained in:
Pasha Bibko
2025-05-03 17:11:09 +01:00
parent eaaceb08d2
commit 3386272f2a
3 changed files with 12 additions and 5 deletions

4
.gitignore vendored
View File

@@ -12,3 +12,7 @@ obj/
*.ll
log
# Ignore user specific options #
.user

View File

@@ -3,15 +3,17 @@ using System.Runtime.InteropServices;
namespace LX_Build
{
internal class LX_API
internal partial class LX_API
{
// Imports SetDllDirectory to change where Dlls are imported from //
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetDllDirectory(string lpPathName);
[LibraryImport("kernel32.dll", EntryPoint = "SetDllDirectoryW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool SetDllDirectory(string lpPathName);
// Imports the Frontend of the compiler //
[DllImport("Generator.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern int GenIR(string arg1, string arg2, string? arg3);
[LibraryImport("Generator.dll", StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int GenIR(string arg1, string arg2, string? arg3);
// Sets the directory to import the DLLs from //
public static void Init()

View File

@@ -7,6 +7,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath></BaseOutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>