ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utility.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactOS Sound System "MME Buddy" Library
00003  * LICENSE:     GPL - See COPYING in the top level directory
00004  * FILE:        lib/sound/mmebuddy/utility.c
00005  *
00006  * PURPOSE:     Provides utility functions used by the library.
00007  *
00008  * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
00009 */
00010 
00011 #include "precomp.h"
00012 
00013 static HANDLE ProcessHeapHandle = NULL;
00014 static UINT   CurrentAllocations = 0;
00015 
00016 /*
00017     Allocates memory, zeroes it, and increases the allocation count.
00018 */
00019 PVOID
00020 AllocateMemory(
00021     IN  UINT Size)
00022 {
00023     PVOID Pointer = NULL;
00024 
00025     if ( ! ProcessHeapHandle )
00026         ProcessHeapHandle = GetProcessHeap();
00027 
00028     Pointer = HeapAlloc(ProcessHeapHandle, HEAP_ZERO_MEMORY, Size);
00029 
00030     if ( ! Pointer )
00031         return NULL;
00032 
00033     ++ CurrentAllocations;
00034 
00035     return Pointer;
00036 }
00037 
00038 /*
00039     Frees memory and reduces the allocation count.
00040 */
00041 VOID
00042 FreeMemory(
00043     IN  PVOID Pointer)
00044 {
00045     SND_ASSERT( ProcessHeapHandle );
00046     SND_ASSERT( Pointer );
00047 
00048     HeapFree(ProcessHeapHandle, 0, Pointer);
00049 
00050     -- CurrentAllocations;
00051 }
00052 
00053 /*
00054     Returns the current number of memory allocations outstanding. Useful for
00055     detecting/tracing memory leaks.
00056 */
00057 UINT
00058 GetMemoryAllocationCount()
00059 {
00060     return CurrentAllocations;
00061 }
00062 
00063 
00064 /*
00065     Count the number of digits in a UINT
00066 */
00067 UINT
00068 GetDigitCount(
00069     IN  UINT Number)
00070 {
00071     UINT Value = Number;
00072     ULONG Digits = 1;
00073 
00074     while ( Value > 9 )
00075     {
00076         Value /= 10;
00077         ++ Digits;
00078     }
00079 
00080     return Digits;
00081 }
00082 
00083 /*
00084     Translate a Win32 error code into an MMRESULT code.
00085 */
00086 MMRESULT
00087 Win32ErrorToMmResult(
00088     IN  UINT ErrorCode)
00089 {
00090     switch ( ErrorCode )
00091     {
00092         case NO_ERROR :
00093         case ERROR_IO_PENDING :
00094             return MMSYSERR_NOERROR;
00095 
00096         case ERROR_BUSY :
00097             return MMSYSERR_ALLOCATED;
00098 
00099         case ERROR_NOT_SUPPORTED :
00100         case ERROR_INVALID_FUNCTION :
00101             return MMSYSERR_NOTSUPPORTED;
00102 
00103         case ERROR_NOT_ENOUGH_MEMORY :
00104             return MMSYSERR_NOMEM;
00105 
00106         case ERROR_ACCESS_DENIED :
00107             return MMSYSERR_BADDEVICEID;
00108 
00109         case ERROR_INSUFFICIENT_BUFFER :
00110             return MMSYSERR_INVALPARAM;
00111 
00112         case ERROR_INVALID_PARAMETER :
00113             return MMSYSERR_INVALPARAM;
00114 
00115 
00116         default :
00117             return MMSYSERR_ERROR;
00118     }
00119 }
00120 
00121 /*
00122     If a function invokes another function, this aids in translating the
00123     result code so that it is applicable in the context of the original caller.
00124     For example, specifying that an invalid parameter was passed probably does
00125     not make much sense if the parameter wasn't passed by the original caller!
00126 
00127     This could potentially highlight internal logic problems.
00128 
00129     However, things like MMSYSERR_NOMEM make sense to return to the caller.
00130 */
00131 MMRESULT
00132 TranslateInternalMmResult(
00133     IN  MMRESULT Result)
00134 {
00135     switch ( Result )
00136     {
00137         case MMSYSERR_INVALPARAM :
00138         case MMSYSERR_INVALFLAG :
00139         {
00140             return MMSYSERR_ERROR;
00141         }
00142     }
00143 
00144     return Result;
00145 }

Generated on Mon May 28 2012 04:17:13 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.