The association between antiretroviral treatment and cardiovascular disease (CVD) risk in HIV-positive persons has been the subject of much debate since the Data collection on Adverse events of Anti-HIV Drugs (D:A:D) study reported that recent use of two antiretroviral drugs, abacavir (ABC) and didanosine (DDI), was associated with increased risk. We focus on the potential impact of DDI use, as this drug has not been as studied intensively as ABC. We propose a flexible marginal structural Cox model with weighted cumulative exposure modeling (Cox WCE MSM) to address two key challenges encountered when using observational longitudinal data to assess the adverse effects of medication: (1) the need to model the cumulative effect of a time-dependent treatment and (2) the need to control for time-dependent confounders that also act as mediators of the effect of past treatment. Simulations confirm that the Cox WCE MSM yields accurate estimates of the causal treatment effect given complex exposure effects and time-dependent confounding. We then use the new flexible Cox WCE MSM to assess the association between DDI use and CVD risk in the Swiss HIV Cohort Study. In contrast to the nonsignificant results obtained with conventional parametric Cox MSMs, our new Cox WCE MSM identifies a significant short-term risk increase due to DDI use in the previous year. Supplementary materials for this article are available online.