My C# library uses p/invoke to call a C dll. There is a compile time switch for the C dll to either use float or double. Is there a way to have the C# dll call functions in the C dll with either float or double values using a switch? Both 32 and 64 bit versions may use either.
Asked
Active
Viewed 48 times
-1
-
Simply import both and decide on a switch (compile or runtime does not matter) which one to use? Presumably its more then just that because the follow up code needs to know if its float or double also. – Ralf May 10 '22 at 13:38
-
C# has a preprocessor, and it supports [conditional compilation](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation), much in the same vein as C and C++. But IMO it'd be better to just build your application around using the double or the float implementation and try and support both – MindSwipe May 10 '22 at 13:40
-
Note in C# you can declare the same function (including ones with DllImport attribute) twice with different parameters (like an overload), ie: `extern static void SomeFunc(double dbl)` *and* `extern static void SomeFunc(float flt)`. And you can create a third managed one that call either one or the other depending on some context. Similar to this https://stackoverflow.com/a/23216851/403671 – Simon Mourier May 10 '22 at 13:50