Snippets tagged interop

  • Async SNTP client

    An asynchronous SNTP client that can retrieve the current time from an internet time server (such as time-a.nist.gov) and optionally update the local system clock to match. Demonstrates async UDP communication, bit-shifting, and native interop/PInvoke.

    12 people like this

    Posted: 7 years ago by Joel Mueller

  • Get COM instances from Running Object Table

    Type extensions for System.Activator which enable the retrieval of COM instances from the Running Object Table.

    1 people like this

    Posted: 7 years ago by Huw Simpson

  • F# yet another Interop example

    Quick demo of using F# to interop with a native C library. C Library has not been checked for algorithm correctness (but works exactly as the origional).

    11 people like this

    Posted: 6 years ago by David Klein

  • Inverse Gamma function and Inverse Factorial by Approximation

    Inverse Gamma function and Inverse Factorial by Approximation based on these references: http://mathforum.org/kb/message.jspa?messageID=342551&tstart=0 https://github.com/DarkoVeberic/LambertW

    2 people like this

    Posted: 3 years ago by Fabio Galuppo

  • C#-Friendly Single-Case Discriminated Unions

    Single-case Discriminated Unions (https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus/) are a lightweight way to create types for important concepts in your domain. Unfortunately, there's a few gotchas when consuming from C# to be aware of. For one, if you use the `==` or `!=` operators in C#, it will do a reference comparison, which is almost certainly not what you want for these wrapper types. By overriding `op_Equality` and `op_Inequality`, this will force it to use a structural comparison. Secondly, when using string concatenation via `+`, `String.Format`, or string interpolation, C# will implicitly convert non-string arguments to a string via `ToString`. This means if you forget to use `.Item` to unwrap your value, you will not get a compiler error, it will just implicitly call `ToString`, which by default will look like this: `Id "c148b684-2c40-4383-a1b9-0e8f37752fd0"`. By overriding `ToString`, we can make sure it will look like the raw underlying type when converted to a string: `c148b684-2c40-4383-a1b9-0e8f37752fd0`.

    0 people like this

    Posted: 3 months ago by Justin Hewlett

  • .NET Interop

    Facilities for interop with languages supporting null.

    3 people like this

    Posted: 7 years ago by Daniel Robinson

  • Higher-Order Functions for Excel

    Some of the standard higher-order functions (like Seq.map, Seq.iter, Seq.filter) but implemented for Excel interop. Effortlessly iterate across ranges of cells, reading them, updating them or formatting them. NB. Type-information won't be displayed correctly on fssnip (Office not installed on server presumably), so to get this working paste the code into VS, make yourself a spreadsheet with a range called 'MyRange' and use FSI to explore.

    16 people like this

    Posted: 6 years ago by Kit Eason

  • Unmanaged memory search

    Useful for pinvoke stuff where your native API requires that you have a unmanaged buffer containing the data you want to work on. Edit: Changed native calls, removed Marshal.Copy (there is a async corner case but I won't delve into it here) and replaced with pinning.

    5 people like this

    Posted: 5 years ago by David Klein

  • Make option type usable in C#

    Using FSharpOption is painful from C#, but it doesn't have to.

    0 people like this

    Posted: 3 years ago by Gauthier Segay