P/invoke with unions in C#

Talks about things to watch out for when using unions in C#

When interop with native code using C# p/invokes, some time you need to create unions in C#. They are represented by structs with [StructLayout(LayoutKind.Explicit)] attribute and the fields annotated with [FieldOffset(0)] specifying their offset. It looks pretty straight-forward, but in practice this can be very deceiving. In this article, I’ll talk about two important rules when using unions.

Embedding CoreCLR in your C/C++ application

Hosting CoreCLR in your C/C++ application

CoreCLR is the runtime that runs your .NET Core application, just like the ‘classic’ .NET in your machine, except it’s much smaller and requires no installation. This makes it ideal for embedding .NET code as part of your application without additional dependency, and you completely are in control of the version of CoreCLR that you are running.

Calling COM code from Go

How to call COM code from Go

In my previous blog I talked about how to call to C functions directly using syscall module, without using Cgo. We can expand this idea a bit further - to call COM objects in Go. As a simple example, let’s see if we can call IMalloc interface implemented in Windows.

Calling C functions from GO

How to call C functions from GO

I’ve recently started learning GO and given that I’ve spent majority of my career in interop between runtimes and languages, I’m naturally curious on how you can interop between GO and other languages. It is most important to have the two functionality below:

  • retrieve a native function pointer
  • call the native function pointer with arguments and receive values back


© 2017. All rights reserved.

Powered by Hydejack v7.5.0