C
C#15mo ago
BattleFrogue

✅ What's the performant way of calling into native DLLs in .NET 7?

Hi, I want to learn about making a library that maps a native DLL to be used in C# (namely the vulkan dll. I know things like Silk.NET exist and the like. I mainly want to do it for the educational purposes). I've had a look online and seen a few examples of doing this, but wanted to know what the most performant way of doing this is in modern versions of .NET where for a library like Vulkan you are making many many calls into the Vulkan library each frame. Any advice is appreciated, thanks. 🙂
7 Replies
BattleFrogue
BattleFrogueOP15mo ago
So generally speaking, just DLLImport'ing the functions I want to use should be just fine?
Kouhai
Kouhai15mo ago
You might wanna use LoadLibrary LibraryImport instead of DLLImport
BattleFrogue
BattleFrogueOP15mo ago
Thanks, I will look into it
Kouhai
Kouhai15mo ago
Sorry, it's LibraryImport not LoadLibrary <a:Sweatyu_GM:913207961701216322> Between LibraryImport and DLLImport? The IL marshaling stub is source generated at compile time instead of runtime
Kouhai
Kouhai15mo ago
Yeah I think it was just introduced in .NET 7, not sure if it existed in .NET 6 but wasn't publicly available or not
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server