Of course if the DRIP is structured as a retirement account, a sale is not a taxable event, and you don't need to calculate the cost basis. That leads nicely to the next caveat. In order to participate in a DRIP inside an IRA, the DRIP sponsor has to be willing to serve as IRA custodian. Some will, some won't. That information is available in the DRIP prospectus, from the company's IR department, or the transfer agent.
Traditional DRIPs are available as company-sponsored plans and from large brokerage houses.
In this arrangement, once you have purchased at least one share, dividends paid on all holdings are used to buy new shares. That first share must be registered in your name, not in street name. When you sell the shares, the company buys the shares back. Note that a company-sponsored DRIP might be run by the company directly, or by a bank. Thus, your investment accumulates a little at a time with no commission.