plugin_wasapi_utils.cxx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 2013 Mamadou DIOP
  2. * Copyright (C) 2013 Doubango Telecom <http://www.doubango.org>
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. */
  19. #include "plugin_wasapi_utils.h"
  20. #include "tsk_debug.h"
  21. bool WASAPIUtils::g_bStarted = false;
  22. HRESULT WASAPIUtils::Startup()
  23. {
  24. if(!g_bStarted) {
  25. HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  26. if(SUCCEEDED(hr) || hr == 0x80010106) { // 0x80010106 when called from managed code (e.g. Boghe) - More info: http://support.microsoft.com/kb/824480
  27. hr = S_OK;
  28. }
  29. g_bStarted = SUCCEEDED(hr);
  30. return hr;
  31. }
  32. return S_OK;
  33. }
  34. HRESULT WASAPIUtils::Shutdown()
  35. {
  36. return S_OK;
  37. }
  38. void WASAPIUtils::PrintError(const char* pcFileName, const char* pcFuncName, unsigned nLineNumber, HRESULT hr)
  39. {
  40. CHAR message[1024] = {0};
  41. #if PLUGIN_WASAPI_UNDER_WINDOWS_RT
  42. // FormatMessageA not allowed on the Store
  43. static WCHAR wBuff[1024] = {0};
  44. FormatMessageW(
  45. FORMAT_MESSAGE_FROM_SYSTEM,
  46. tsk_null,
  47. hr,
  48. 0,
  49. wBuff,
  50. sizeof(wBuff)-1,
  51. tsk_null);
  52. WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, wBuff, wcslen(wBuff), message, sizeof(message) - 1, NULL, NULL);
  53. #else
  54. #ifdef _WIN32_WCE
  55. FormatMessage
  56. #else
  57. FormatMessageA
  58. #endif
  59. (
  60. #if !PLUGIN_WASAPI_UNDER_WINDOWS_RT
  61. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  62. #endif
  63. FORMAT_MESSAGE_FROM_SYSTEM,
  64. tsk_null,
  65. hr,
  66. 0,
  67. message,
  68. sizeof(message) - 1,
  69. tsk_null);
  70. #endif
  71. TSK_DEBUG_ERROR("[WASAPI] File:%s\n Function=%s\n Line:%u\n Message:%s", pcFileName, pcFuncName, nLineNumber, message);
  72. }