✅ Using a C# DLL in C++
im actually trying to call a C# dll from c++ with DllExport, the c++ code return no error but dont execute the functions, here is the source :
C# :
C++ :
The cpp code says that it got executed but it doesn't really
29 Replies
you can't do this this way, C# isn't compiled to native code
there's a whole runtime you need to set up first
how do i compile to native code
you can't, not in a way that will work for this
what's your actual goal?
just to make a C# library for C++
but why
i mean, if you really want to this is a starting point https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting
Write a custom .NET runtime host - .NET
Learn to host the .NET runtime from native code to support advanced scenarios that require controlling how the .NET runtime works.
this might be of your interest https://github.com/3F/DllExport/wiki/Quick-start
GitHub
Quick start
.NET DllExport with .NET Core support (aka 3F/DllExport aka DllExport.bat) - 3F/DllExport
You could make a native aot library
https://luxeengine.com/csharp-to-native-library/
it does nothing when i run the code
it dont even print "Dll Executed!"
thanks for ur response, ill try that
well that doesn't look like its using that library
it has videos and abunch of step by steps u can look into
it stops when calling the function
yeah but your code is not using the library from waht u showed...
wdym
I linked u a library, with their quick start on how to use it
and ur just quoting me on not working with some code that doesn't look like what the library provides
i clicker on " C++ ❤ C# (+📹)"
the link at the right
its not just code u need to use the library
u understand that right?
?
it dont work
oh this is working for u
did you build it like the article said?
yeah, i added <PublishAOT> to true
but this is the same thing as compiling in vs code ?
tbh i compiled with vs
i will try that
publishing is not the same as compiling
yeah my bad
just remember, its in your
publish
folder (mine in the screenshot is in C:\Users\Dawn\RiderProjects\NAOTTest\NAOTTest\bin\Release\net7.0\win-x64\publish
)@
bro thank you this is working well
thanks a lot
:okHand:
just remember, native aot (c# native) has some drawbacks, from the top of my head um, reflection is a nono, Json serialization gets harder, and some other things, i forgor
though i could be wrong, im a whole version of .net behind on native aot, they might have gotten better already
/solved
!solved
bruh
i think its /close or smthn