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)
17 static HANDLE ProcessHeapHandle
= NULL
;
18 static UINT CurrentAllocations
= 0;
21 Allocates memory, zeroes it, and increases the allocation count.
29 if ( ! ProcessHeapHandle
)
30 ProcessHeapHandle
= GetProcessHeap();
32 Pointer
= HeapAlloc(ProcessHeapHandle
, HEAP_ZERO_MEMORY
, Size
);
37 ++ CurrentAllocations
;
43 Frees memory and reduces the allocation count.
49 SND_ASSERT( ProcessHeapHandle
);
50 SND_ASSERT( Pointer
);
52 HeapFree(ProcessHeapHandle
, 0, Pointer
);
54 -- CurrentAllocations
;
58 Returns the current number of memory allocations outstanding. Useful for
59 detecting/tracing memory leaks.
62 GetMemoryAllocationCount()
64 return CurrentAllocations
;
69 Count the number of digits in a UINT
88 Translate a Win32 error code into an MMRESULT code.
97 case ERROR_IO_PENDING
:
98 return MMSYSERR_NOERROR
;
101 return MMSYSERR_ALLOCATED
;
103 case ERROR_NOT_SUPPORTED
:
104 case ERROR_INVALID_FUNCTION
:
105 return MMSYSERR_NOTSUPPORTED
;
107 case ERROR_NOT_ENOUGH_MEMORY
:
108 return MMSYSERR_NOMEM
;
110 case ERROR_ACCESS_DENIED
:
111 return MMSYSERR_BADDEVICEID
;
113 case ERROR_INSUFFICIENT_BUFFER
:
114 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
;