@blakeyrat said in Arithmetics...:
In any case, I don't know the answer to your question. Look it up. But if it is required, since Attributes in C# are just methods, it'd be easy enough to write a version that checks the ".dll" path and if there's no file there also checks the ".so" path. So it's not like a huge emergency anyway.
Warning ry ahead, my apologies in advance...
Attributes in C# are actually classes, usually annotating to a runtime or framework that something non-default is appropriate. In the case at hand the DllImportAttribute is applied to a static extern
method. When code tries to call the static extern
method the .Net runtime will read the (properties on the) annotation and perform the LoadLibrary/GetProcAddress dance to get to the actual code, and uses other properties and annotations to determine the calling convention for the method, the string format (length-prefixed, zero terminated, COM, single/multi/unicode/utf-8 encoding), it takes care that objects are pinned in memory (i.e. can't be moved by the garbage collector) for the duration of the method call, and a whole lot more.
The runtime is free to take the dllname as 'hint', e.g. mono on linux translates DllName.dll
to libDllName.so
, and supports a "dll mapping" configuration, for those cases where it's not that simple.
On the .Net framework, depending on some parameters, the proc name is adapted at runtime - name + 'A'
on ANSI based, name + 'W'
on Unicode based Windows'.
All that said, and while it is an interesting subject, it is quite a pain to work with (there's a reason someone started pinvoke.net). Everything is so much easier when it is in the same eco-system and runtime. And if you must use it you always try to isolate it as much as possible from the rest of your code.