// Import WINAPI import win32.windows; // Core API import core.runtime; import std.range; import std.string; // FMOD import fmod.fmod; extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int result; void exceptionHandler(Throwable e) { throw e; } try { Runtime.initialize(&exceptionHandler); result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); Runtime.terminate(&exceptionHandler); } catch (Error o) { MessageBoxA(null, cast(char *) o.toString(), "Error", MB_OK | MB_ICONEXCLAMATION); result = 0;// failed } return result; } int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Foo foo = new Foo; return (foo !is null); } class Foo { public: this() { //m_sound = new Sound(r"C:\acdc.ogg"); } ~this() { MessageBoxA(null, "Never Called", "Error", MB_OK | MB_ICONEXCLAMATION); } private: Sound m_sound; } class Sound { public: static this() { if(FMOD_System_Create(&m_system) != FMOD_RESULT.FMOD_OK) throw new Error("Failed to create fmod system."); if(FMOD_System_Init(m_system, 2, FMOD_INIT_NORMAL, null) != FMOD_RESULT.FMOD_OK) throw new Error("Failed to initialize fmod."); } static ~this() { // Close and release system (omitting these prevents any errors from occuring) FMOD_System_Close(m_system); FMOD_System_Release(m_system); } this(string file) { if(FMOD_System_CreateSound(m_system, cast(char *) file.toStringz, FMOD_HARDWARE | FMOD_LOOP_OFF, null, &m_sound) != FMOD_RESULT.FMOD_OK) throw new Error("Failed to create sound."); } ~this() { // Release Sound FMOD_Sound_Release(m_sound); } private: static FMOD_SYSTEM * m_system; FMOD_SOUND * m_sound; }