Programmers encounter often this problem, and have to be creative for finding the reason - that's what makes programming so interesting. Sometimes more interesting than you'd prefer.
Typical reason for those symptoms is writing into a wrong memory area. Either it happens directly in your code, f.i. exceeding an array length or using invalid pointers. Or it's a damaged image, model, or sound file that you're loading. Wrong content of such a file causes memory areas to be overwritten by the loading functions of the DirectX or Windows API.
Both problems often don't crash immediately, but some time later when the overwritten memory area is accessed by a totally different function.
Try to find a code configuration where the crash always happens, or at least often. Then replace all loaded files step by step by a dummy file. This way you can find a file problem. If the crash then still happens, check all suspicious parts of your code.
Some common hints can also be found here:
http://manual.3dgamestudio.net/debugging.htm