Right all the initializeation is done before the program enters the real time loop. Therefore everything is already defined.
lpddsPrimary being the surface that is defined with the palette lpddp.
I have fixed the problem it was to do with what some of you were saying.
lpddsPrimary->Lock(NULL,&theSurface, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR , NULL);
I simply put this in a if statement with a failed function, and now there is no error. I would be most grateful if something could explain why this results in solving the error.
Code:
if (FAILED(lpddsPrimary->Lock(NULL,&theSurface, DDLOCK_WAIT |
DDLOCK_SURFACEMEMORYPTR , NULL)))
return 0;