Closed
Description
I have a simple project in .NET Core 8.0 and a simple test project in C++.
I have two simple exported functions
using System;
using System.Runtime.InteropServices;
namespace ExportsDemo
{
public static class Exports
{
[DllExport(CallingConvention.StdCall)]
public static Int32 DemoProc1()
{
return 1337;
}
[DllExport(CallingConvention.StdCall)]
public static Int32 DemoProc2()
{
DateTime t = DateTime.Now;
return 1338;
}
}
}
First function DemoProc1 is working, the second DemoProc2 is failing with the exception 0xE0434352.
#include <iostream>
#include <windows.h>
typedef int32_t(__stdcall* tDemoProc)();
int main()
{
HINSTANCE hGetProcIDDLL = LoadLibraryA("ExportsDemo.dll");
if (!hGetProcIDDLL) {
std::cout << "could not load the dynamic library" << std::endl;
return EXIT_FAILURE;
}
// resolve function address here
tDemoProc DemoProc1 = (tDemoProc)GetProcAddress(hGetProcIDDLL, "DemoProc1");
if (!DemoProc1) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
tDemoProc DemoProc2 = (tDemoProc)GetProcAddress(hGetProcIDDLL, "DemoProc2");
if (!DemoProc2) {
std::cout << "could not locate the function" << std::endl;
return EXIT_FAILURE;
}
// OK
std::cout << DemoProc1() << std::endl;
// Exception
std::cout << DemoProc2() << std::endl;
}
Unhandled exception at 0x00007FF839C1B699 (KernelBase.dll) in UseDemo.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FF81C9F0000).
Running on console
Unhandled exception: System.IO.FileNotFoundException: Could not load file or assembly System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies. The system cannot find the file specified.
Both projects are configured as x64.
I have Use our IL Assembler
and Rebase System Object: System.Runtime -> mscorlib
enabled.
C:\>dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
DllExport -version
: v1.7.4.29858+c1cc52f- Used Visual Studio 2022 Version 17.12.1
Demo Project:
DLLCoreExportsDemo.zip