Exporting a Swift function in a Windows DLL

Is it possible to export functions written in a Swift class library [Windows] as ordinary DLL © functions consumable by any language?
I’ve tried to create public Swift function, but they are not included in the exported symbols of the DLL.

Thanks in advance.

Luca

Are you building an Island dll project or an Echoes (ie .NET) one? I don’t think you can export plain Win32-level methods from a .NET dll.

Hi,

if it’s .NET you can do something like:

import System.Collections.Generic
import System.Linq
import System.Text
import System.Threading.Tasks

public class Class1 {
    @UnmanagedExport("name", System.Runtime.InteropServices.CallingConvention.Cdecl)
    static func test() {}
}

The parameters to UnmanagedExport are optional, the first is the name, the second the calling convention. It defaults to the name of the function and winapi.

It does require “Unsafe Code” to be enabled, and it requires you to build for either x86 or x86_64.

If it’s java you need to use JNI. For Island the DllExport attribute can be used.

I have created a Island Class Library project which, once built, creates a
.dll file along with the .fx. but the DLL file when opened with Dependency
Walker shows that the export list is empty.
I read that in a Island C# DLL project you can use the DllExport attribute.
My question is: is there an equivalent of DllExport in Swift?

Thanks,

Luca

Yes. The same attribute but with @ before it, like @DllExport(Parameters)

Thanks a lot! Now it works! I combined DllExport, SymbolName and
CallingConvention to achieve what I needed.
The only thing I still miss is the ability to have a “plain C” exported
name i.e. without the mangling which adds “@nn” at the end of the name of
the function.

Luca

Change it to cdecl on both ends. STDcall always has @

ie:

@DllExport
@CallingConvention(CallingConvention.Cdecl)
@SymbolName('Test')
func test() {
}