2 * PROJECT: ReactOS Sound System "MME Buddy" Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/sound/mmebuddy/utility.c
6 * PURPOSE: Provides utility functions used by the library.
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
13 static HANDLE ProcessHeapHandle
= NULL
;
14 static UINT CurrentAllocations
= 0;
17 Allocates memory, zeroes it, and increases the allocation count.
25 if ( ! ProcessHeapHandle
)
26 ProcessHeapHandle
= GetProcessHeap();
28 Pointer
= HeapAlloc(ProcessHeapHandle
, HEAP_ZERO_MEMORY
, Size
);
33 ++ CurrentAllocations
;
39 Frees memory and reduces the allocation count.
45 SND_ASSERT( ProcessHeapHandle
);
46 SND_ASSERT( Pointer
);
48 HeapFree(ProcessHeapHandle
, 0, Pointer
);
50 -- CurrentAllocations
;
54 Returns the current number of memory allocations outstanding. Useful for
55 detecting/tracing memory leaks.
58 GetMemoryAllocationCount()
60 return CurrentAllocations
;
65 Count the number of digits in a UINT
84 Translate a Win32 error code into an MMRESULT code.
93 case ERROR_IO_PENDING
:
94 return MMSYSERR_NOERROR
;
97 return MMSYSERR_ALLOCATED
;
99 case ERROR_NOT_SUPPORTED
:
100 case ERROR_INVALID_FUNCTION
:
101 return MMSYSERR_NOTSUPPORTED
;
103 case ERROR_NOT_ENOUGH_MEMORY
:
104 return MMSYSERR_NOMEM
;
106 case ERROR_ACCESS_DENIED
:
107 return MMSYSERR_BADDEVICEID
;
109 case ERROR_INSUFFICIENT_BUFFER
:
110 return MMSYSERR_INVALPARAM
;
112 case ERROR_INVALID_PARAMETER
:
113 return MMSYSERR_INVALPARAM
;
117 return MMSYSERR_ERROR
;
122 If a function invokes another function, this aids in translating the
123 result code so that it is applicable in the context of the original caller.
124 For example, specifying that an invalid parameter was passed probably does
125 not make much sense if the parameter wasn't passed by the original caller!
127 This could potentially highlight internal logic problems.
129 However, things like MMSYSERR_NOMEM make sense to return to the caller.
132 TranslateInternalMmResult(
137 case MMSYSERR_INVALPARAM
:
138 case MMSYSERR_INVALFLAG
:
140 return MMSYSERR_ERROR
;