Everything works perfectly if I write the DLL in C++ (and I've never had any errors with C++ DLL's before that are similar to this one). If I remove the cast line and MessageBox()'s in the D version, then I still get the error.