Use the c++ APIs.

No functionality change.
Fixed formatting.