WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
DOFManager.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4 using System.Reflection;
5 using System.Windows.Forms;
6 using System.IO;
7 using System.Runtime.InteropServices;
8 
9 namespace PinballX
10 {
11  public class DOFManager
12  {
13 
14 
15  Type DOFType;
16  object DOF;
17  object DOFLocker = new object();
18 
19  public void Load()
20  {
21 
22  lock (DOFLocker)
23  {
24  if (DOF == null)
25  {
26  try
27  {
28  DOFType = Type.GetTypeFromProgID("DirectOutput.ComObject", true);
29 
30  }
31  catch (Exception E)
32  {
33 
34  throw new Exception("Could not find the DirectOutput.ComObject. Please check if the DirectOutputComObject is registered.", E);
35  }
36 
37 
38  try
39  {
40  DOF = Activator.CreateInstance(DOFType);
41 
42  }
43  catch (Exception E)
44  {
45 
46  throw new Exception("Could not create a instance of the DirectOutput framework. " + E.Message);
47  }
48 
49  }
50  }
51  }
52 
53 
54  public void Unload()
55  {
56  lock (DOFLocker)
57  {
58 
59  if (DOF != null)
60  {
61  // Marshal.ReleaseComObject(DOF);
62  DOF = null;
63  DOFType = null;
64  }
65  }
66  }
67 
68 
69 
70  public bool IsInitialized { get; private set; }
71 
72  public string GetVersion()
73  {
74  lock (DOFLocker)
75  {
76  if (DOF != null)
77  {
78  return (string)DOFType.InvokeMember("GetVersion", BindingFlags.InvokeMethod, null, DOF, null);
79  }
80  return "";
81  }
82  }
83 
84  public string GetDllPath()
85  {
86  lock (DOFLocker)
87  {
88  if (DOF != null)
89  {
90  return (string)DOFType.InvokeMember("GetDllPath", BindingFlags.InvokeMethod, null, DOF, null);
91  }
92  return "";
93  }
94  }
95 
96  //public string GetName()
97  //{
98  // if (GetNameDel != null)
99  // {
100  // return GetNameDel();
101  // }
102  // return "";
103  //}
104  //public string GetDllPath()
105  //{
106  // if (GetDllPathDel != null)
107  // {
108  // return GetDllPathDel();
109  // }
110  // return "";
111  //}
112  public void Finish()
113  {
114  lock (DOFLocker)
115  {
116  if (DOF != null && IsInitialized)
117  {
118  DOFType.InvokeMember("Finish", BindingFlags.InvokeMethod, null, DOF, null);
119  IsInitialized = false;
120  }
121  Unload();
122  }
123  }
124  public void UpdateTableElement(string TableElementTypeChar, int Number, int Value)
125  {
126  lock (DOFLocker)
127  {
128  if (DOF != null && IsInitialized)
129  {
130  object[] Args = new object[] { TableElementTypeChar, Number, Value };
131  DOFType.InvokeMember("UpdateTableElement", BindingFlags.InvokeMethod, null, DOF, Args);
132 
133  }
134  }
135  }
136  public void UpdateNamedTableElement(string TableElementName, int Value)
137  {
138  lock (DOFLocker)
139  {
140  if (DOF != null & IsInitialized)
141  {
142  object[] Args = new object[] { TableElementName, Value };
143  DOFType.InvokeMember("UpdateNamedTableElement", BindingFlags.InvokeMethod, null, DOF, Args);
144  }
145  }
146  }
147 
148  public void SignalNamedTableElement(string TableElementName)
149  {
150  lock (DOFLocker)
151  {
152  if (DOF != null & IsInitialized)
153  {
154  object[] Args = new object[] { TableElementName, 1 };
155  DOFType.InvokeMember("UpdateNamedTableElement", BindingFlags.InvokeMethod, null, DOF, Args);
156  Args = new object[] { TableElementName, 0 };
157  DOFType.InvokeMember("UpdateNamedTableElement", BindingFlags.InvokeMethod, null, DOF, Args);
158  }
159  }
160  }
161 
162  public void Init()
163  {
164  lock (DOFLocker)
165  {
166  Load();
167  if (DOF != null && !IsInitialized)
168  {
169 
170  object[] Args = new object[] { "PinballX", "", "PinballX" };
171  DOFType.InvokeMember("Init", BindingFlags.InvokeMethod, null, DOF, Args);
172 
173  IsInitialized = true;
174  }
175  }
176  }
177 
178 
179 
181  {
182  lock (DOFLocker)
183  {
184  Load();
185  if (DOF != null && IsInitialized)
186  {
187 
188  return (string[])DOFType.InvokeMember("GetConfiguredTableElmentDescriptors", BindingFlags.InvokeMethod, null, DOF, null);
189  }
190  return new string[0];
191  }
192  }
193 
194 
195  public string GetTableMappingFilename()
196  {
197  lock (DOFLocker)
198  {
199  Load();
200  if (DOF != null && IsInitialized)
201  {
202  return (string)DOFType.InvokeMember("TableMappingFileName", BindingFlags.InvokeMethod, null, DOF, null);
203  }
204  return null;
205  }
206 
207  }
208 
209  }
210 }
void SignalNamedTableElement(string TableElementName)
Definition: DOFManager.cs:148
string GetVersion()
Definition: DOFManager.cs:72
string GetTableMappingFilename()
Definition: DOFManager.cs:195
string GetDllPath()
Definition: DOFManager.cs:84
void UpdateTableElement(string TableElementTypeChar, int Number, int Value)
Definition: DOFManager.cs:124
void UpdateNamedTableElement(string TableElementName, int Value)
Definition: DOFManager.cs:136
string[] GetConfiguredTableElmentDescriptors()
Definition: DOFManager.cs:180