E:\sandbox\ktraunmueller\compositor\Sources\Win\WinSupport\Sources\Windows\Com+Interop.swift:19:39: error: value of type 'IInitializeWithWindow' has no member 'lpVtbl'
try CHECKED(pThis.pointee.lpVtbl.pointee.Initialize(pThis, hwnd))
~~~~~~~~~~~~~ ^~~~~~
Looking up the definition (ctrl-clicking IInitializeWithWindow opens WinSDK.Shell.swiftinterface) shows that the lpVtbl property is defined, however:
public struct IInitializeWithWindow {
public init()
public init(lpVtbl: UnsafeMutablePointer<IInitializeWithWindowVtbl>!)
public var lpVtbl: UnsafeMutablePointer<IInitializeWithWindowVtbl>!
}
What am I missing?
Thanks in advance.
Edit: I’m on a fairly recent 6.3-dev TBC toolchain (20250930.2)
>swift -version
Swift version 6.3-dev (LLVM 75c6640ca938538, Swift 761b88fe9ad462c)
Target: aarch64-unknown-windows-msvc
Build config: +assertions
Do you have C++ interop enabled? If so, I would expect the COM class/interface to be projected directly onto pThis instead of indirectly through .pointee.lpVtbl.
And no, the type of pThis is UnsafeMutablePointer<IInitializeWithWindow>:
E:\sandbox\ktraunmueller\compositor\Sources\Win\WinSupport\Sources\Windows\Com+Interop.swift:20:31: error: value of type 'UnsafeMutablePointer<IInitializeWithWindow>' has no member 'Initialize'
try CHECKED(pThis.Initialize(hwnd))
~~~~~ ^~~~~~~~~~
(Note sure if this matters, but technically using the COM moniker wasn’t correct on my side, this is actually WinRT, not COM)
When C++ interop is enabled, the Windows headers don't include a lpVtbl member in COM types because it's the vtable of the C++ class instead. So if the type is projected into Swift as UnsafeMutablePointer<ISomething>, try pThis.pointee.Initialize(hwnd) instead?
E:\sandbox\ktraunmueller\compositor\Sources\Win\WinSupport\Sources\Windows\Com+Interop.swift:20:39: error: 'Initialize' is unavailable: virtual function is not available in Swift because it is pure
try CHECKED(pThis.pointee.Initialize(hwnd))
^~~~~~~~~~
C:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um\shobjidl_core.h:32191:43: note: 'Initialize' has been explicitly marked unavailable here
virtual HRESULT STDMETHODCALLTYPE Initialize(
I tried switching over my project to C (from C++)
cmake_minimum_required(VERSION 3.29)
project(WinInterop LANGUAGES C)
and call through the C style API, but that gives the original error (hinting that I am still compiling the module with __cplusplus defined).
But this already helped me a lot, thanks for pointing me in the right direction!