Ignore:
Timestamp:
Oct 25, 2001, 12:47:43 AM (24 years ago)
Author:
sandervl
Message:

dynamically load MDM.DLL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/winmm/initwinmm.cpp

    r6640 r7196  
    1 /* $Id: initwinmm.cpp,v 1.3 2001-09-05 10:30:21 bird Exp $
     1/* $Id: initwinmm.cpp,v 1.4 2001-10-24 22:47:41 sandervl Exp $
    22 *
    33 * WINMM DLL entry point
     
    2828#define  INCL_DOSPROCESS
    2929#define  INCL_DOSSEMAPHORES
    30 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
     30#define  INCL_DOSERRORS
     31#define  INCL_OS2MM
     32#include <os2wrap.h>   //Odin32 OS/2 api wrappers
     33#include <os2mewrap.h> //Odin32 OS/2 MMPM/2 api wrappers
    3134#include <stdlib.h>
    3235#include <stdio.h>
     
    4346#include "waveoutbase.h"
    4447#include <win\options.h>
     48#include "initwinmm.h"
    4549
    4650#define DBG_LOCALLOG    DBG_initterm
     
    5862}
    5963static HMODULE dllHandle = 0;
     64static HMODULE MMPMLibraryHandle = 0;
     65
     66BOOL fMMPMAvailable = FALSE;
     67
     68DWORD (APIENTRY *pfnmciSendCommand)(WORD   wDeviceID,
     69                                   WORD   wMessage,
     70                                   DWORD  dwParam1,
     71                                   PVOID  dwParam2,
     72                                   WORD   wUserParm) = NULL;
     73DWORD (APIENTRY *pfnmciGetErrorString)(DWORD   dwError,
     74                                      LPSTR   lpstrBuffer,
     75                                      WORD    wLength) = NULL;
    6076
    6177//******************************************************************************
     
    6379BOOL WINAPI LibMainWinmm(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
    6480{
    65   static BOOL           bInitDone = FALSE;
     81  static BOOL bInitDone = FALSE;
     82  char   szError[CCHMAXPATH];
    6683
    6784  switch (fdwReason)
     
    85102        dwVolume = (dwVolume << 16) | dwVolume;
    86103        WaveOut::setDefaultVolume(dwVolume);
     104
     105        // try to load the MDM library, not MMPM directly!!!
     106        if (DosLoadModule(szError, sizeof(szError),
     107                          "MDM.DLL", &MMPMLibraryHandle) != NO_ERROR)
     108        {
     109            // this system has no MMPM :-(
     110            fMMPMAvailable = FALSE;
     111        }
     112        else
     113        {
     114            /* detect if MMPM is available */
     115            if (DosQueryProcAddr(MMPMLibraryHandle,
     116                                 1, /* ORD_MCISENDCOMMAND */
     117                                 NULL,
     118                                (PFN*)&pfnmciSendCommand) != NO_ERROR)
     119            {
     120                fMMPMAvailable = FALSE;
     121            }
     122            else
     123            {
     124                fMMPMAvailable = TRUE;
     125            }
     126
     127            /* see if we can get the address for the mciGetErrorString function */
     128            if (fMMPMAvailable == TRUE)
     129            {
     130                if (DosQueryProcAddr(MMPMLibraryHandle,
     131                                     3, /* ORD_MCIGETERRORSTRING */
     132                                     NULL,
     133                                     (PFN*)&pfnmciGetErrorString) != NO_ERROR)
     134                    pfnmciGetErrorString = NULL;
     135            }
     136            dprintf(("MMPM/2 is available; hmod %x", MMPMLibraryHandle));
     137            dprintf(("mciSendCommand    %x", pfnmciSendCommand));
     138            dprintf(("mciGetErrorString %x", pfnmciGetErrorString));
     139        }
     140
    87141        return TRUE;
    88142   }
     
    96150        auxOS2Close(); /* SvL: Close aux device if necessary */
    97151        IRTMidiShutdown;  /* JT: Shutdown RT Midi subsystem, if running. */
     152
     153        if(MMPMLibraryHandle) DosFreeModule(MMPMLibraryHandle);
    98154        return TRUE;
    99155   }
     
    144200//******************************************************************************
    145201//******************************************************************************
    146 
    147 
    148 
     202DWORD APIENTRY mymciSendCommand(WORD   wDeviceID,
     203                                WORD   wMessage,
     204                                DWORD  dwParam1,
     205                                PVOID  dwParam2,
     206                                WORD   wUserParm)
     207{
     208    if(pfnmciSendCommand == NULL) {
     209        DebugInt3();
     210        return MCIERR_CANNOT_LOAD_DRIVER;
     211    }
     212    USHORT sel = GetFS();
     213    DWORD ret = pfnmciSendCommand(wDeviceID, wMessage, dwParam1, dwParam2, wUserParm);
     214    SetFS(sel);
     215    return ret;
     216}
     217//******************************************************************************
     218//******************************************************************************
     219DWORD APIENTRY mymciGetErrorString(DWORD   dwError,
     220                                   LPSTR   lpstrBuffer,
     221                                   WORD    wLength)
     222{
     223    if(pfnmciGetErrorString == NULL) {
     224        DebugInt3();
     225        return MCIERR_CANNOT_LOAD_DRIVER;
     226    }
     227    USHORT sel = GetFS();
     228    DWORD ret = pfnmciGetErrorString(dwError, lpstrBuffer, wLength);
     229    SetFS(sel);
     230    return ret;
     231}
     232//******************************************************************************
     233//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.