|
请教Direct Music的问题
bool Init(HWND hWnd)
{
char pathStr[MAX_PATH]; // path for audio file
WCHAR wcharStr[MAX_PATH];
// create the loader object
if (FAILED(CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8, (void**)&dmusicLoader)))
{
MessageBox(hwnd, "Unable to create the IDirectMusicLoader8 object!\nPress OK to exit",
"ERROR!", MB_OK);
return false;
}
// create the performance object
if (FAILED(CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC,
IID_IDirectMusicPerformance8, (void**)&dmusicPerformance)))
{
MessageBox(hwnd, "Unable to create the IDirectMusicPerformance8 object!\nPress OK to exit",
"ERROR!", MB_OK);
return false;
}
// initialize the performance with the standard audio path
dmusicPerformance->InitAudio(NULL, NULL, hwnd, DMUS_APATH_SHARED_STEREOPLUSREVERB, 64,
DMUS_AUDIOF_ALL, NULL);
// create a standard 3D audiopath
if (FAILED(dmusicPerformance->CreateStandardAudioPath(DMUS_APATH_DYNAMIC_3D,
64, TRUE, &dmusic3DAudioPath)))
{
MessageBox(hwnd, "Unable to create standard 3D audiopath! Press OK to exit",
"ERROR!", MB_OK);
return false;
}
// retrieve the listener from the audiopath
if (FAILED(dmusic3DAudioPath->GetObjectInPath(0, DMUS_PATH_PRIMARY_BUFFER, 0, GUID_NULL, 0,
IID_IDirectSound3DListener8,
(void**)&ds3DListener)))
{
MessageBox(hwnd, "Unable to retrieve the listener! Press OK to exit",
"ERROR!", MB_OK);
return false;
}
// get the listener parameters
dsListenerParams.dwSize = sizeof(DS3DLISTENER);
ds3DListener->GetAllParameters(&dsListenerParams);
// set position of listener
dsListenerParams.vPosition.x = 0.0f;
dsListenerParams.vPosition.y = 0.0f;
dsListenerParams.vPosition.z = 0.0f;
ds3DListener->SetAllParameters(&dsListenerParams, DS3D_IMMEDIATE);
// retrieve the current directory
GetCurrentDirectory(MAX_PATH, pathStr);
// convert to unicode string
MultiByteToWideChar(CP_ACP, 0, pathStr, -1, wcharStr, MAX_PATH);
// set the search directory
dmusicLoader->SetSearchDirectory(GUID_DirectMusicAllTypes, wcharStr, FALSE);
return true;
}
请教一下,为什么我用下面这个函数初始化DirectX会出现错误:
// create the loader object
if (FAILED(CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC,
IID_IDirectMusicLoader8, (void**)&dmusicLoader)))
{
MessageBox(hwnd, "Unable to create the IDirectMusicLoader8 object!\nPress OK to exit",
"ERROR!", MB_OK);
return false;
}
|
|