Convert to c++ api (previously mixing C and C++ apis)