equal
deleted
inserted
replaced
63 |
63 |
64 // the segment object is where the MIDI data is stored for playback |
64 // the segment object is where the MIDI data is stored for playback |
65 IDirectMusicSegment *segment = NULL; |
65 IDirectMusicSegment *segment = NULL; |
66 |
66 |
67 // the loader bject can load many types of DMusic related files |
67 // the loader bject can load many types of DMusic related files |
68 IDirectMusicLoader *loader = NULL; |
68 IDirectMusicLoader *loader = NULL; |
69 |
69 |
70 // whether we've initialized COM or not (when deciding whether to shut down) |
70 // whether we've initialized COM or not (when deciding whether to shut down) |
71 int COMInitialized = 0; |
71 int COMInitialized = 0; |
72 |
72 |
73 |
73 |
79 HRESULT (WINAPI *CoInitialize)( LPVOID pvReserved ); |
79 HRESULT (WINAPI *CoInitialize)( LPVOID pvReserved ); |
80 void (WINAPI *CoUninitialize)( ); |
80 void (WINAPI *CoUninitialize)( ); |
81 }; |
81 }; |
82 |
82 |
83 #define M(x) x "\0" |
83 #define M(x) x "\0" |
84 static const char ole_files[] = |
84 static const char ole_files[] = |
85 M("ole32.dll") |
85 M("ole32.dll") |
86 M("CoCreateInstance") |
86 M("CoCreateInstance") |
87 M("CoInitialize") |
87 M("CoInitialize") |
88 M("CoUninitialize") |
88 M("CoUninitialize") |
89 M("") |
89 M("") |
93 |
93 |
94 static ProcPtrs _proc; |
94 static ProcPtrs _proc; |
95 |
95 |
96 static bool LoadOleDLL() |
96 static bool LoadOleDLL() |
97 { |
97 { |
98 if (_proc.CoCreateInstance != NULL) |
98 if (_proc.CoCreateInstance != NULL) |
99 return true; |
99 return true; |
100 if (!LoadLibraryList((void**)&_proc, ole_files)) |
100 if (!LoadLibraryList((void**)&_proc, ole_files)) |
101 return false; |
101 return false; |
102 return true; |
102 return true; |
103 } |
103 } |
149 |
149 |
150 // now we'll create the loader object. This will be used to load the |
150 // now we'll create the loader object. This will be used to load the |
151 // midi file for our demo. Again, we need to use CoCreateInstance |
151 // midi file for our demo. Again, we need to use CoCreateInstance |
152 // and pass the appropriate ID parameters |
152 // and pass the appropriate ID parameters |
153 if (FAILED(_proc.CoCreateInstance((REFCLSID)CLSID_DirectMusicLoader, |
153 if (FAILED(_proc.CoCreateInstance((REFCLSID)CLSID_DirectMusicLoader, |
154 NULL, CLSCTX_INPROC, |
154 NULL, CLSCTX_INPROC, |
155 (REFIID)IID_IDirectMusicLoader, |
155 (REFIID)IID_IDirectMusicLoader, |
156 (LPVOID *)&loader))) { |
156 (LPVOID *)&loader))) { |
157 MSGBOX("Failed to create loader object"); |
157 MSGBOX("Failed to create loader object"); |
158 return false; |
158 return false; |
159 } |
159 } |
161 // that's it for initialization. If we made it this far we |
161 // that's it for initialization. If we made it this far we |
162 // were successful. |
162 // were successful. |
163 return true; |
163 return true; |
164 } |
164 } |
165 |
165 |
166 // Releases memory used by all of the initialized |
166 // Releases memory used by all of the initialized |
167 // DirectMusic objects in the program |
167 // DirectMusic objects in the program |
168 void ReleaseSegment (void) |
168 void ReleaseSegment (void) |
169 { |
169 { |
170 if (NULL != segment) { |
170 if (NULL != segment) { |
171 segment->Release (); |
171 segment->Release (); |
172 segment = NULL; |
172 segment = NULL; |
173 } |
173 } |
174 } |
174 } |
175 void ShutdownDirectMusic (void) |
175 void ShutdownDirectMusic (void) |
176 { |
176 { |
177 // release everything but the segment, which the performance |
177 // release everything but the segment, which the performance |
178 // will release automatically (and it'll crash if it's been |
178 // will release automatically (and it'll crash if it's been |
179 // released already) |
179 // released already) |
180 |
180 |
181 if (NULL != loader) { |
181 if (NULL != loader) { |
182 loader->Release (); |
182 loader->Release (); |
183 loader = NULL; |
183 loader = NULL; |
194 _proc.CoUninitialize(); |
194 _proc.CoUninitialize(); |
195 COMInitialized = 0; |
195 COMInitialized = 0; |
196 } |
196 } |
197 } |
197 } |
198 |
198 |
199 // Load MIDI file for playing |
199 // Load MIDI file for playing |
200 bool LoadMIDI (char *directory, char *filename) |
200 bool LoadMIDI (char *directory, char *filename) |
201 { |
201 { |
202 DMUS_OBJECTDESC obj_desc; |
202 DMUS_OBJECTDESC obj_desc; |
203 WCHAR w_directory[_MAX_PATH]; // utf-16 version of the directory name. |
203 WCHAR w_directory[_MAX_PATH]; // utf-16 version of the directory name. |
204 WCHAR w_filename[_MAX_PATH]; // utf-16 version of the file name |
204 WCHAR w_filename[_MAX_PATH]; // utf-16 version of the file name |
227 // release the existing segment if we have any |
227 // release the existing segment if we have any |
228 if (NULL != segment) |
228 if (NULL != segment) |
229 ReleaseSegment(); |
229 ReleaseSegment(); |
230 |
230 |
231 // and make a new segment |
231 // and make a new segment |
232 if (FAILED(loader->GetObject(&obj_desc, |
232 if (FAILED(loader->GetObject(&obj_desc, |
233 (REFIID)IID_IDirectMusicSegment, |
233 (REFIID)IID_IDirectMusicSegment, |
234 (LPVOID *) &segment))) { |
234 (LPVOID *) &segment))) { |
235 MSGBOX("LoadMIDI: Get object failed"); |
235 MSGBOX("LoadMIDI: Get object failed"); |
236 return FALSE; |
236 return FALSE; |
237 } |
237 } |
238 |
238 |