游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3836|回复: 1

请教Direct Music的问题

[复制链接]

1

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2009-3-5 18:13:00 | 显示全部楼层 |阅读模式
请教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;
}

3

主题

53

帖子

104

积分

注册会员

Rank: 2

积分
104
发表于 2009-3-6 13:28:00 | 显示全部楼层

Re: 请教Direct Music的问题

看来你没有初始化COM的缘故,CoInitialize(NULL);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2024-11-24 13:01

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表