]> Repos - portaudio/commitdiff
wasapi:
authordmitrykos <dmitrykos@0f58301d-fd10-0410-b4af-bbb618454e57>
Tue, 2 Mar 2010 17:42:36 +0000 (17:42 +0000)
committerdmitrykos <dmitrykos@0f58301d-fd10-0410-b4af-bbb618454e57>
Tue, 2 Mar 2010 17:42:36 +0000 (17:42 +0000)
- removed dependency from strsafe.h
- fixed crash in InitializeHostApis() if PaWasapi_Initialize() failed due to internal WASAPI error (error code was returned as paNoError in such case)

src/hostapi/wasapi/pa_win_wasapi.cpp

index 4315dcf3c59306119c4ccd34c7f92eaac6c3758c..9c243e2aebb51f59702e77423218c759ed90f712 100644 (file)
 \r
 #define WIN32_LEAN_AND_MEAN // exclude rare headers\r
 #include <windows.h>\r
+#include <stdio.h>\r
 #include <process.h>\r
 #include <mmsystem.h>\r
 #include <MMReg.h>  // must be before other Wasapi headers\r
 #if _MSC_VER >= 1400\r
-       #include <strsafe.h>\r
        #include <Avrt.h>\r
        #include <audioclient.h>\r
        #include <Endpointvolume.h>\r
@@ -134,16 +134,16 @@ typedef BOOL   (WINAPI *FAvRevertMmThreadCharacteristics)(HANDLE);
 typedef BOOL   (WINAPI *FAvSetMmThreadPriority)          (HANDLE,AVRT_PRIORITY);\r
 \r
 static HMODULE hDInputDLL = 0;\r
-FAvRtCreateThreadOrderingGroup   pAvRtCreateThreadOrderingGroup=0;\r
-FAvRtDeleteThreadOrderingGroup   pAvRtDeleteThreadOrderingGroup=0;\r
-FAvRtWaitOnThreadOrderingGroup   pAvRtWaitOnThreadOrderingGroup=0;\r
-FAvSetMmThreadCharacteristics    pAvSetMmThreadCharacteristics=0;\r
-FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics=0;\r
-FAvSetMmThreadPriority           pAvSetMmThreadPriority=0;\r
-\r
-#define setupPTR(fun, type, name)  {                                                        \\r
+FAvRtCreateThreadOrderingGroup   pAvRtCreateThreadOrderingGroup = NULL;\r
+FAvRtDeleteThreadOrderingGroup   pAvRtDeleteThreadOrderingGroup = NULL;\r
+FAvRtWaitOnThreadOrderingGroup   pAvRtWaitOnThreadOrderingGroup = NULL;\r
+FAvSetMmThreadCharacteristics    pAvSetMmThreadCharacteristics = NULL;\r
+FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics = NULL;\r
+FAvSetMmThreadPriority           pAvSetMmThreadPriority = NULL;\r
+\r
+#define _GetProc(fun, type, name)  {                                                        \\r
                                         fun = (type) GetProcAddress(hDInputDLL,name);       \\r
-                                        if(fun == NULL) {                                   \\r
+                                        if (fun == NULL) {                                  \\r
                                             PRINT(("GetProcAddr failed for %s" ,name));     \\r
                                             return false;                                   \\r
                                         }                                                   \\r
@@ -527,15 +527,15 @@ static __forceinline UINT32 GetFramesSleepTime(UINT32 nFrames, UINT32 nSamplesPe
 static bool SetupAVRT()\r
 {\r
     hDInputDLL = LoadLibraryA("avrt.dll");\r
-    if(hDInputDLL == NULL)\r
+    if (hDInputDLL == NULL)\r
         return false;\r
 \r
-    setupPTR(pAvRtCreateThreadOrderingGroup,  FAvRtCreateThreadOrderingGroup,  "AvRtCreateThreadOrderingGroup");\r
-    setupPTR(pAvRtDeleteThreadOrderingGroup,  FAvRtDeleteThreadOrderingGroup,  "AvRtDeleteThreadOrderingGroup");\r
-    setupPTR(pAvRtWaitOnThreadOrderingGroup,  FAvRtWaitOnThreadOrderingGroup,  "AvRtWaitOnThreadOrderingGroup");\r
-    setupPTR(pAvSetMmThreadCharacteristics,   FAvSetMmThreadCharacteristics,   "AvSetMmThreadCharacteristicsA");\r
-       setupPTR(pAvRevertMmThreadCharacteristics,FAvRevertMmThreadCharacteristics,"AvRevertMmThreadCharacteristics");\r
-    setupPTR(pAvSetMmThreadPriority,          FAvSetMmThreadPriority,          "AvSetMmThreadPriority");\r
+    _GetProc(pAvRtCreateThreadOrderingGroup,  FAvRtCreateThreadOrderingGroup,  "AvRtCreateThreadOrderingGroup");\r
+    _GetProc(pAvRtDeleteThreadOrderingGroup,  FAvRtDeleteThreadOrderingGroup,  "AvRtDeleteThreadOrderingGroup");\r
+    _GetProc(pAvRtWaitOnThreadOrderingGroup,  FAvRtWaitOnThreadOrderingGroup,  "AvRtWaitOnThreadOrderingGroup");\r
+    _GetProc(pAvSetMmThreadCharacteristics,   FAvSetMmThreadCharacteristics,   "AvSetMmThreadCharacteristicsA");\r
+       _GetProc(pAvRevertMmThreadCharacteristics,FAvRevertMmThreadCharacteristics,"AvRevertMmThreadCharacteristics");\r
+    _GetProc(pAvSetMmThreadPriority,          FAvSetMmThreadPriority,          "AvSetMmThreadPriority");\r
     \r
        return pAvRtCreateThreadOrderingGroup && \r
                pAvRtDeleteThreadOrderingGroup && \r
@@ -647,7 +647,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
 \r
     CoInitialize(NULL);\r
 \r
-    PaError result = paNoError;\r
+    PaError result = paUnanticipatedHostError;\r
     PaWasapiHostApiRepresentation *paWasapi;\r
     PaDeviceInfo *deviceInfoArray;\r
 \r
@@ -697,7 +697,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                                WCHAR* pszDeviceId = NULL;\r
                                hResult = defaultRenderer->GetId(&pszDeviceId);\r
                                IF_FAILED_JUMP(hResult, error);\r
-                               StringCchCopyW(paWasapi->defaultRenderer, MAX_STR_LEN-1, pszDeviceId);\r
+                               wcscpy_s(paWasapi->defaultRenderer, MAX_STR_LEN-1, pszDeviceId);\r
                                CoTaskMemFree(pszDeviceId);\r
                                defaultRenderer->Release();\r
                        }\r
@@ -716,7 +716,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                                WCHAR* pszDeviceId = NULL;\r
                                hResult = defaultCapturer->GetId(&pszDeviceId);\r
                                IF_FAILED_JUMP(hResult, error);\r
-                               StringCchCopyW(paWasapi->defaultCapturer, MAX_STR_LEN-1, pszDeviceId);\r
+                               wcscpy_s(paWasapi->defaultCapturer, MAX_STR_LEN-1, pszDeviceId);\r
                                CoTaskMemFree(pszDeviceId);\r
                                defaultCapturer->Release();\r
                        }\r
@@ -767,7 +767,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
                 WCHAR* pszDeviceId = NULL;\r
                 hResult = paWasapi->devInfo[i].device->GetId(&pszDeviceId);\r
                 IF_FAILED_JUMP(hResult, error);\r
-                StringCchCopyW(paWasapi->devInfo[i].szDeviceID, MAX_STR_LEN-1, pszDeviceId);\r
+                wcscpy_s(paWasapi->devInfo[i].szDeviceID, MAX_STR_LEN-1, pszDeviceId);\r
                 CoTaskMemFree(pszDeviceId);\r
 \r
                 if (lstrcmpW(paWasapi->devInfo[i].szDeviceID, paWasapi->defaultCapturer) == 0)\r
@@ -938,7 +938,7 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd
 \r
     SAFE_RELEASE(pEndPoints);\r
 \r
-    return result;\r
+    return (result = paNoError);\r
 \r
 error:\r
 \r