You cannot avoid DLL errors if you are programming windows drivers or using some driver api in your application , else use Java.
There is no real, clean way to avoid DLL errors other than avoiding DLLs. If you are writing the DLLs within your own application things are easier.