import every function from a C module
Recently found out about DllImport, thought about using it to bind stuff, but im rather unsure how to go about things, following this example, it looks to me like you can only add one function per DllImport, do i have to call it multiple time?
this is the example i found
found an answer to my question but its ten years old so i'd assume it would be good by now
https://stackoverflow.com/questions/15781627/c-one-attribute-for-multiple-declarations-dllimport
Stack Overflow
C#: One attribute for multiple declarations (DLLImport)
I'm using the [DLLImport] attribute to access a bunch of C++ functions in my .NET code.
For now, I have all the functions in the following way:
const string DLL_Path = "path\to\my\dll.dll";
[
4 Replies
No, it's still one to one relationship... One DllImport per function, is it annoying? If you have many functions, yes 😄
for that reason there are source generatora like CsWin32 to do this for you. also in current C# its a little better to use LibraryImport instead (basically the same thing)
By the title of the thread. There are libraries / plugins that can do winapi functions pretty good, as listed above, CsWin32 (A source geneerator)
there's also nuget packages like Vanara.PInvoke
If you plan to target non-winapi libs, you could try out https://github.com/dotnet/ClangSharp
If you plan to target non-winapi libs, you could try out https://github.com/dotnet/ClangSharp
GitHub
GitHub - dotnet/ClangSharp: Clang bindings for .NET written in C#
Clang bindings for .NET written in C#. Contribute to dotnet/ClangSharp development by creating an account on GitHub.
Downsides of things like Vanara.PInvoke or ClangSharp would be that you import all functions rather than only used functions, (bigger build binary) but you do get intelli-sense
Though you could remove unused generated bindings in ClangSharp