Solutionunvalidated
MemorySegment result = (MemorySegment) hLoadLibraryW.invokeExact(capturedState, lpLibName); — capturedState is the first argument to hLoadLibraryW before the normal args. Tension: This would also work. Outcome: bind the state variable as first arg.
f4f97ece-3a29-4347-af1b-a575e05d3a1a
MemorySegment result = (MemorySegment) hLoadLibraryW.invokeExact(capturedState, lpLibName); — capturedState is the first argument to hLoadLibraryW before the normal args. Tension: This would also work. Outcome: bind the state variable as first arg.