A measurement of CP-violating observables is performed using the decays B± → DK± and B± → Dπ±, where the D meson is reconstructed in one of the self-conjugate three-body final states K0Sπ+π− and K0SK+K− (commonly denoted K0Sh+h−). The decays are analysed in bins of the D-decay phase space, leading to a measurement that is independent of the modelling of the D-decay amplitude. The observables are inter- preted in terms of the CKM angle γ. Using a data sample corresponding to an integrated luminosity of 9 fb−1 collected in proton-proton collisions at centre-of mass energies of 7, 8, and 13 TeV with the LHCb experiment, γ is measured to be (68.7+5.2−5.1)∘. The hadronic parameters rDKB,rDπB,δDKB,andδDπB, which are the ratios and strong-phase differences of the suppressed and favoured B± decays, are also reported.