人气 103

请教Direct Music的问题 [复制链接] [复制链接]

九艺网 2017-4-24 13:04:40

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
请教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;
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

QQ|手机版|小黑屋|九艺游戏动画论坛 ( 津ICP备2022000452号-1 )

GMT+8, 2024-5-3 18:05 , Processed in 0.128460 second(s), 23 queries .

Powered by Discuz! X3.4  © 2001-2017 Discuz Team.