Ignore:
Timestamp:
Dec 13, 2011, 11:17:52 AM (14 years ago)
Author:
dmik
Message:

Port DSOUND to GCC/kBuild.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/gcc-kmk/src/dsound/initterm.cpp

    r21842 r21878  
    1 /* $Id: initdsound.cpp,v 1.1 2002-09-14 08:31:25 sandervl Exp $
     1/* $Id: initterm.cpp,v 1.18 2002-09-14 08:31:25 sandervl Exp $
    22 *
    3  * DLL entry point
     3 * DSOUND DLL entry point
    44 *
    55 * Copyright 1998 Sander van Leeuwen
    66 * Copyright 1998 Peter Fitzsimmons
    77 *
    8  *
    98 * Project Odin Software License can be found in LICENSE.TXT
    10  *
    119 */
    1210
    13 /*-------------------------------------------------------------*/
    14 /* INITERM.C -- Source for a custom dynamic link library       */
    15 /*              initialization and termination (_DLL_InitTerm) */
    16 /*              function.                                      */
    17 /*                                                             */
    18 /* When called to perform initialization, this sample function */
    19 /* gets storage for an array of integers, and initializes its  */
    20 /* elements with random integers.  At termination time, it     */
    21 /* frees the array.  Substitute your own special processing.   */
    22 /*-------------------------------------------------------------*/
    23 
    24 
    25 /* Include files */
    2611#define  INCL_DOSMODULEMGR
    2712#define  INCL_DOSPROCESS
     
    4328#include "initdsound.h"
    4429
    45 extern "C" {
    46  //Win32 resource table (produced by wrc)
    47  extern DWORD _Resource_PEResTab;
    48 }
     30// Win32 resource table (produced by wrc)
     31extern DWORD dsound_PEResTab;
    4932
    5033static HMODULE dllHandle = 0;
    5134static HMODULE MMPMLibraryHandle = 0;
     35
     36char dsoundPath[CCHMAXPATH] = "";
    5237
    5338BOOL fdsMMPMAvailable = TRUE;
     
    6247                                      WORD    wLength) = NULL;
    6348
    64 
    65 //******************************************************************************
    66 //******************************************************************************
    6749BOOL WINAPI LibMainDSound(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
    6850{
    69   char   szError[CCHMAXPATH];
    70   HKEY   hKey;
     51    char   szError[CCHMAXPATH];
     52    HKEY   hKey;
    7153
    72    switch (fdwReason)
    73    {
    74    case DLL_PROCESS_ATTACH:
     54    switch (fdwReason)
     55    {
     56    case DLL_PROCESS_ATTACH:
    7557
    76         if(fdsMMPMAvailable == TRUE)
    77         {//if audio access wasn't disabled already, check if mmpm2 is installed
     58        if(fdsMMPMAvailable == TRUE)
     59        {
     60            // if audio access wasn't disabled already, check if mmpm2 is installed
    7861            // try to load the MDM library, not MMPM directly!!!
    7962            if (DosLoadModule(szError, sizeof(szError),
     
    8265                // this system has no MMPM :-(
    8366                fdsMMPMAvailable = FALSE;
    84             } 
     67            }
    8568            else
    8669            {
     
    8972                                     1, /* ORD_MCISENDCOMMAND */
    9073                                     NULL,
    91                                     (PFN*)&pfnDSmciSendCommand) != NO_ERROR)
     74                                     (PFN*)&pfnDSmciSendCommand) != NO_ERROR)
    9275                {
    9376                    fdsMMPMAvailable = FALSE;
    94                 } 
     77                }
    9578                else
    9679                {
     
    11396        }
    11497
    115         if(fdsMMPMAvailable && RegOpenKeyA(HKEY_LOCAL_MACHINE, CUSTOM_BUILD_OPTIONS_KEY, &hKey) == 0) 
     98        if(fdsMMPMAvailable && RegOpenKeyA(HKEY_LOCAL_MACHINE, CUSTOM_BUILD_OPTIONS_KEY, &hKey) == 0)
    11699        {
    117100            DWORD dwSize, dwType;
     
    135118        return TRUE;
    136119
    137    case DLL_THREAD_ATTACH:
    138    case DLL_THREAD_DETACH:
     120    case DLL_THREAD_ATTACH:
     121    case DLL_THREAD_DETACH:
    139122        return TRUE;
    140123
    141    case DLL_PROCESS_DETACH:
     124    case DLL_PROCESS_DETACH:
    142125        if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
    143126        return TRUE;
    144    }
    145    return FALSE;
     127    }
     128    return FALSE;
    146129}
    147 /****************************************************************************/
    148 /* _DLL_InitTerm is the function that gets called by the operating system   */
    149 /* loader when it loads and frees this DLL for each process that accesses   */
    150 /* this DLL.  However, it only gets called the first time the DLL is loaded */
    151 /* and the last time it is freed for a particular process.  The system      */
    152 /* linkage convention MUST be used because the operating system loader is   */
    153 /* calling this function.                                                   */
    154 /****************************************************************************/
    155 ULONG APIENTRY inittermDSound(ULONG hModule, ULONG ulFlag)
    156 {
    157 
    158    /*-------------------------------------------------------------------------*/
    159    /* If ulFlag is zero then the DLL is being loaded so initialization should */
    160    /* be performed.  If ulFlag is 1 then the DLL is being freed so            */
    161    /* termination should be performed.                                        */
    162    /*-------------------------------------------------------------------------*/
    163 
    164    switch (ulFlag) {
    165       case 0 :
    166       {
    167          dllHandle = RegisterLxDll(hModule, LibMainDSound, (PVOID)&_Resource_PEResTab);
    168          if(dllHandle == 0)
    169                 return 0UL;
    170 
    171          dprintf(("dsound init %s %s (%x)", __DATE__, __TIME__, inittermDSound));
    172          break;
    173       }
    174 
    175       case 1 :
    176          if(dllHandle) {
    177                 UnregisterLxDll(dllHandle);
    178          }
    179          break;
    180       default  :
    181          return 0UL;
    182    }
    183 
    184    /***********************************************************/
    185    /* A non-zero value must be returned to indicate success.  */
    186    /***********************************************************/
    187    return 1UL;
    188 }
    189 //******************************************************************************
    190 //******************************************************************************
    191130
    192131DWORD APIENTRY dsmciSendCommand(WORD   wDeviceID,
     
    205144    return ret;
    206145}
    207 //******************************************************************************
    208 //******************************************************************************
     146
    209147DWORD APIENTRY dsmciGetErrorString(DWORD   dwError,
    210148                                   LPSTR   lpstrBuffer,
     
    220158    return ret;
    221159}
    222 //******************************************************************************
    223 //******************************************************************************
     160
     161ULONG SYSTEM DLL_InitDSound(ULONG hModule)
     162{
     163    DosQueryModuleName(hModule, CCHMAXPATH, dsoundPath);
     164    char *endofpath = strrchr(dsoundPath, '\\');
     165    if (endofpath)
     166        *(endofpath+1) = 0;
     167
     168    CheckVersionFromHMOD(PE2LX_VERSION, hModule); /*PLF Wed  98-03-18 05:28:48*/
     169
     170    dllHandle = RegisterLxDll(hModule, LibMainDSound, (PVOID)&dsound_PEResTab);
     171    if(dllHandle == 0)
     172        return -1;
     173
     174    dprintf(("dsound init %s %s (%x)", __DATE__, __TIME__, DLL_InitDSound));
     175
     176    return 0;
     177}
     178
     179void SYSTEM DLL_TermDSound(ULONG hModule)
     180{
     181    if (dllHandle)
     182       UnregisterLxDll(dllHandle);
     183}
     184
     185ULONG SYSTEM DLL_Init(ULONG hModule)
     186{
     187    if (DLL_InitDefault(hModule) == -1)
     188        return -1;
     189    return DLL_InitDSound(hModule);
     190}
     191
     192void SYSTEM DLL_Term(ULONG hModule)
     193{
     194    DLL_TermDSound(hModule);
     195    DLL_TermDefault(hModule);
     196}
Note: See TracChangeset for help on using the changeset viewer.