예제 #1
0
bool _al_win_init_touch_input_api(void)
{
   /* Reference counter will be negative if we already tried to initialize the driver.
    * Lack of touch input API is persistent state, so do not test for it again. */
   if (touch_input_api_reference_counter < 0)
      return false;

   /* Increase API reference counter if it is already initialized. */
   if (touch_input_api_reference_counter > 0)
   {
      touch_input_api_reference_counter++;
      return true;
   }

   /* Open handle to user32.dll. This one should be always present. */
   user32_module = _al_open_library("user32.dll");
   if (NULL == user32_module)
      return false;

   _al_win_close_touch_input_handle = (CLOSETOUCHINPUTHANDLEPROC)_al_import_symbol(user32_module, "CloseTouchInputHandle");
   _al_win_get_touch_input_info     = (GETTOUCHINPUTINFOPROC)    _al_import_symbol(user32_module, "GetTouchInputInfo");
   _al_win_is_touch_window          = (ISTOUCHWINDOWPROC)        _al_import_symbol(user32_module, "IsTouchWindow");
   _al_win_register_touch_window    = (REGISTERTOUCHWINDOWPROC)  _al_import_symbol(user32_module, "RegisterTouchWindow");
   _al_win_unregister_touch_window  = (UNREGISTERTOUCHWINDOWPROC)_al_import_symbol(user32_module, "UnregisterTouchWindow");

   if (NULL == _al_win_close_touch_input_handle || NULL == _al_win_get_touch_input_info  ||
       NULL == _al_win_is_touch_window          || NULL == _al_win_register_touch_window ||
       NULL == _al_win_unregister_touch_window) {

      _al_close_library(user32_module);

      _al_win_close_touch_input_handle = NULL;
      _al_win_get_touch_input_info     = NULL;
      _al_win_is_touch_window          = NULL;
      _al_win_register_touch_window    = NULL;
      _al_win_unregister_touch_window  = NULL;

      /* Mark as 'do not try this again'. */
      touch_input_api_reference_counter = -1;
	  ALLEGRO_WARN("failed loading the touch input API\n");
      return false;
   }

   /* Set initial reference count. */
   touch_input_api_reference_counter = 1;
   ALLEGRO_INFO("touch input API installed successfully\n");
   return true;
}
/* The open method starts up the driver and should lock the device, using the
   previously set paramters, or defaults. It shouldn't need to start sending
   audio data to the device yet, however. */
static int _dsound_open()
{
   HRESULT hr;

   ALLEGRO_DEBUG("Loading DirectSound module\n");

   /* load DirectSound module */
   _al_dsound_module = _al_open_library(_al_dsound_module_name);
   if (_al_dsound_module == NULL) {
      ALLEGRO_ERROR("Failed to open '%s' library\n", _al_dsound_module_name);
      return 1;
   }

   /* import DirectSound create proc */
   _al_dsound_create = (DIRECTSOUNDCREATE8PROC)_al_import_symbol(_al_dsound_module, "DirectSoundCreate8");
   if (_al_dsound_create == NULL) {
      ALLEGRO_ERROR("DirectSoundCreate8 not in %s\n", _al_dsound_module_name);
      _al_close_library(_al_dsound_module);
      return 1;
   }

   ALLEGRO_INFO("Starting DirectSound...\n");

   /* FIXME: Use default device until we have device enumeration */
   hr = _al_dsound_create(NULL, &device, NULL);
   if (FAILED(hr)) {
      ALLEGRO_ERROR("DirectSoundCreate8 failed\n");
      _al_close_library(_al_dsound_module);
      return 1;
   }

   ALLEGRO_DEBUG("DirectSoundCreate8 succeeded\n");

   /* FIXME: The window specified here is probably very wrong. NULL won't work either. */
   hr = device->SetCooperativeLevel(GetForegroundWindow(), DSSCL_PRIORITY);
   if (FAILED(hr)) {
      ALLEGRO_ERROR("SetCooperativeLevel failed\n");
      _al_close_library(_al_dsound_module);
      return 1;
   }

   return 0;
}