How do I access the cannon outside the castle?
I believe you're talking about the cannon outside the castle in Super Mario 64 - this cannon will launch you up to a secret area, but only if you've got all 120 stars.
For getting all the stars and accessing this secret cannon:
Yoshi is up on top of the castle, and if you get up there, he'll hook you up with many extra lives :)