I have previously successfully used Unmanaged Exports and DllExport to use .NET DLL files with Inno Setup.
However now I am trying to get it to work with DNNE.
I have the following C# code targeting x86
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnableDynamicLoading>true</EnableDynamicLoading>
<Platforms>x86</Platforms>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DNNE" Version="1.0.31" />
</ItemGroup>
</Project>
using System.Runtime.InteropServices;
namespace DNNETest
{
internal static class NativeMethods
{
[DllImport("User32.dll", EntryPoint = "MessageBox",
CharSet = CharSet.Auto)]
internal static extern int MsgBox(
IntPtr hWnd, string lpText, string lpCaption, uint uType);
}
public class Class1
{
[UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvStdcall) })]
public static void Test()
{
_ = NativeMethods.MsgBox(IntPtr.Zero, "Hello from C#", ":)", 0);
return;
}
}
}
I made a small console app to verify the exported code is working correctly:
using System.Runtime.InteropServices;
NE.Test();
public static class NE
{
[DllImport("DNNETestNE", CallingConvention = CallingConvention.StdCall)]
public extern static void Test();
}
Works OK!
Now I try to move it to Inno Setup:
[Files]
Source: Files\Dotnet\DNNETest.deps.json; Flags: dontcopy
Source: Files\Dotnet\DNNETest.dll; Flags: dontcopy
Source: Files\Dotnet\DNNETest.runtimeconfig.json; Flags: dontcopy
Source: Files\Dotnet\DNNETestNE.dll; Flags: dontcopy
procedure Test();
external 'Test@{tmp}\DNNETestNE.dll stdcall delayload';
procedure InitializeDotnet;
begin
ExtractTemporaryFiles('{tmp}\DNNETest.deps.json');
ExtractTemporaryFiles('{tmp}\DNNETest.dll');
ExtractTemporaryFiles('{tmp}\DNNETest.runtimeconfig.json');
ExtractTemporaryFiles('{tmp}\DNNETestNE.dll');
Test();
end;
Will crash with Could not call proc
I also tried
external 'Test@{tmp}\DNNETestNE.dll,DNNETest.dll stdcall delayload loadwithalteredsearchpath';
Played around with combinations of AnyCPU, x86, x64 but to no avail
But same error
I am unsure what else I can try, since these steps were working ok with the other DllImport packages.