Swift – Checking unmanaged address book single value property for nil

If I want the values associated with various properties, I use the following syntax: let first = ABRecordCopyValue(person, kABPersonFirstNameProperty)?.takeRetainedValue() as? String let last = ABRecordCopyValue(person, kABPersonLastNameProperty)?.takeRetainedValue() as? String Or you can use optional binding: if let first = ABRecordCopyValue(person, kABPersonFirstNameProperty)?.takeRetainedValue() as? String { // use `first` here } if let last = ABRecordCopyValue(person, kABPersonLastNameProperty)?.takeRetainedValue() as? … Read more

Is there a tool that generates P/Invoke signatures for arbitrary unmanaged DLL?

Google quickly found http://www.pinvoker.com (Wayback) (Compatiblity listed as VS2005, 2008, and 2010; it doesn’t seem to have been updated to work with newer versions) Microsoft’s C++/CLI compiler can also do this, if you use /clr:safe and #include the header file, it will generate p/invoke code which you can extract with e.g. ILSpy (free) or Red … Read more

How to call managed code from unmanaged code?

Look at this solution: https://sites.google.com/site/robertgiesecke/Home/uploads/unmanagedexports The solution allows to call C# function from C by decorating your function with [DllExport] attribute (opposite of P/Invoke DllImport). Exmaple: C# code class Test { [DllExport(“add”, CallingConvention = CallingConvention.StdCall)] public static int Add(int left, int right) { return left + right; } } C code: extern “C” int add(int, … Read more

C# “Unmanaged Exports” [closed]

I would recommend you do this the documented way instead of relying on a undocumented hack from an author who doesn’t provide support. Let’s do it with an example: namespace Publics { public class Class1 { public static void Run() { // Stuff… } } } Add a new C++/CLI class library to your project. … Read more

Howto implement callback interface from unmanaged DLL to .net app?

You don’t need to use Marshal.GetFunctionPointerForDelegate(), the P/Invoke marshaller does it automatically. You’ll need to declare a delegate on the C# side whose signature is compatible with the function pointer declaration on the C++ side. For example: using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; class UnManagedInterop { private delegate int Callback(string text); private Callback mInstance; // … Read more