Your error description is to unspecific. My best tip is to restart development from the scratch because it looks like some severe bug like mismatched handle or access rights.
Read the
Building a Basic v4 Printer Driver documentation and start from some sample code.
Best is, to make only small steps and test them regularly.