Confined nanocrystallization of active pharmaceutical ingredients