WinCe PlaySound每次都不起作用

问题描述 投票:1回答:1

我的设备WinCE 5.0有问题。我需要从资源中播放声音。

BOOL PlayResource (int lpName) 
{ 
  BOOL bRtn; 
  LPTSTR lpRes; 
  HANDLE hResInfo, hRes; 
  HINSTANCE     hInst = AfxGetInstanceHandle();

  // Find the wave resource.
  hResInfo = FindResource (hInst, MAKEINTRESOURCE(lpName), L"WAVE"); 

  if (hResInfo == NULL) 
  {
      filePlay = false;
    return FALSE; 
  }
  // Load the wave resource. 
  hRes = LoadResource (hInst, HRSRC(hResInfo)); 

  if (hRes == NULL) 
  {
      filePlay = false;
    return FALSE; 
  }
  // Lock the wave resource and play it. 
  lpRes = (LPTSTR)LockResource (hRes);

  if (lpRes != NULL) 
    { 
    bRtn = PlaySound(lpRes,GetModuleHandle(NULL), SND_MEMORY | SND_SYNC  | SND_NODEFAULT); 
    DWORD err = GetLastError();
    Logger::getInstance().log(Logger::LOG_INFO, "PlaySound return: %d error: %d", bRtn, err);
    } 
  else 
    bRtn = 0; 

  filePlay = false;
  return bRtn; 
}

PlaySound每次都不起作用。 bRtn每次都返回1,但每次都没有播放声音。 GetLastError()始终获取代码120

c++ windows-ce
1个回答
0
投票

更改

bRtn = PlaySound(lpRes,GetModuleHandle(NULL), SND_MEMORY | SND_SYNC  | SND_NODEFAULT);

要么

bRtn = PlaySound(lpRes, NULL, SND_MEMORY | SND_SYNC  | SND_NODEFAULT);

或者

bRtn = PlaySound(MAKEINTRESOURCE(lpName), hInst, SND_RESOURCE | SND_SYNC  | SND_NODEFAULT);

在最后一种情况下,你甚至不需要在调用PlaySound之前将声音加载到内存中。

© www.soinside.com 2019 - 2024. All rights reserved.