A 'long code' is just a normal phone number (full MSISDN in e.164 format) You can get one by purchasing a SIM card (in the case of GSM -- you have to get the whole phone in CDMA today as they don't use SIM like identity modules yet). Once you have that you can get a GSM modem and use standard COM programming for the modem to send and receive SMS messages. Last I looked the cheapest carrier for this in the US was T-Mobile with an unlimited messaging plan.
As Barry pointed out you are not supposed to use this method for commercial purposes, but my experience working at an SMS aggregator was that a lot of people are doing it this way. Check the fine print in the contract to make sure you know what 'unlimited' really means, also be mindful that the speed of a GSM modem is not so good for large scale operations. For large commercial applications you may need to look at connecting to an aggregator. But then you have to negotiate the solution with the aggregator and operator so you might not be able to use a long code.