When you say codes, I assume that you're talking about serials.
The best way that I have heard for ensuring that people aren't able to pirate your software, is to have the business logic on a secure server that you own. So the software would use a web reference to your server, do some validation of the serial and then the server is sent the information to be processed, it processes it and sends back the result, which is then displayed to the user.
Obviously if you just use a serial that matches a argorithm then that could be shared, so what you would probably want to do is have a serial, which is registered, which takes some hardware specific information about the machine that it is being run on and that unique serial/hardware information is stored in a database on the server and used for the authentication.
If you combine those two things then you have a pretty damn secure system, but there are a couple problems;
1) It means that the application will always have to be connected to the internet in order to be use
2) You would have to check several hardware serial codes so that if they change their graphics card but everything else stays the same then they can still use the system.
3) You would need to ensure that your server has high availability as if the customers aren't able to use your application because your server is down they wont be happy
I hope that this helps
Satal