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 *.ll
log log
# Ignore user specific options #
.user

View File

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

View File

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