It is possible for a newly patentable idea to include other already patented ideas. To understand the guidelines for obtaining a patent, read the primer on What the Law Says . You should realize that if you are using someone else's patented products to enable your patent, you will need to get a license or other permission from the owner of that patent. To learn about patent licensing, read the patent licensing and sales section. There are two options - copyright and patents, and both can be used to defend software.
Patents prevent the unique functionality of the code from being copied.
Read the Software section of the Schoolhouse for more info. All creative work should be documented using some sort of inventor's notebook - this is recommended by the United States Patent and Trademark Office. Yes, a copyright protects the form of the expression, so independently created expressions of the same ideas are protectable. Learn about copyright law here . Learn about protecting software here .