After you create the palette, you pass the pointer to the DirectDrawPalette object (ddpal) to the primary surface by calling the IDirectDrawSurface3::SetPalette method, as shown in the following example:
ddrval = lpDDSPrimary->SetPalette(lpDDPal);
if(ddrval != DD_OK)
// SetPalette failed.
After you have called IDirectDrawSurface3::SetPalette, the DirectDrawPalette object is associated with the DirectDrawSurface object. Any time you need to change the palette, you simply create a new palette and set the palette again. (Although this tutorial uses these steps, there are other ways of changing the palette, as will be shown in later examples.)