1 /** \file   joy-win32-dinput-handle.c
2  * \brief   Functionality shared by DirectInput joystick and mouse drivers
3  *
4  * \author  Fabrizio Gennari <fabrizio.ge@tiscali.it>
5  */
6 
7 /*
8  * This file is part of VICE, the Versatile Commodore Emulator.
9  * See README for copyright notice.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  *  02111-1307  USA.
25  *
26  */
27 
28 #include "vice.h"
29 
30 #include "debug_gtk3.h"
31 
32 #ifdef WIN32_COMPILE
33 
34 #ifndef HAVE_GUIDLIB
35 /* all GUIDs will be defined in this object file */
36 #define INITGUID
37 /* else all GUIDs will be defined in the external library dxguid.lib */
38 #endif
39 
40 /* for CoInitializeEx */
41 #ifndef HAVE_DINPUT_LIB
42 #define _WIN32_DCOM
43 #endif
44 
45 #include "joy-win32-dinput-handle.h"
46 
47 #ifdef HAVE_DINPUT
48 
49 /* #include "winmain.h" */
50 
51 static LPDIRECTINPUT di = NULL;
52 
get_directinput_handle(void)53 LPDIRECTINPUT get_directinput_handle(void)
54 {
55 #if 0 /* FIXME */
56     NOT_IMPLEMENTED();
57 #else
58 #ifndef HAVE_DINPUT_LIB
59     HRESULT res;
60 #endif
61 
62     if (di == NULL) {
63 
64         HINSTANCE winmain_instance = GetModuleHandle(NULL); /* FIXME */
65 
66 #ifdef HAVE_DINPUT_LIB
67         if (DirectInputCreate(winmain_instance, 0x0500, &di, NULL) != DI_OK) {
68             di = NULL;
69         }
70 #else
71         CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
72 
73         res = CoCreateInstance(&CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectInput2A, (PVOID*)&di);
74         if (res != S_OK) {
75             return NULL;
76         }
77         if (IDirectInput_Initialize(di, winmain_instance, 0x0500) != S_OK) {
78             IDirectInput_Release(di);
79             di = NULL;
80         }
81 #endif
82     }
83 #endif /* FIXME */
84     return di;
85 }
86 #endif
87 #endif
88