@@ -22,6 +22,11 @@ public API(IntPtr rm)
22
22
m_Rm = rm ;
23
23
}
24
24
25
+ static public implicit operator API ( IntPtr rm )
26
+ {
27
+ return new Rainmeter . API ( rm ) ;
28
+ }
29
+
25
30
[ DllImport ( "Rainmeter.dll" , CharSet = CharSet . Unicode ) ]
26
31
private extern static IntPtr RmReadString ( IntPtr rm , string option , string defValue , bool replaceMeasures ) ;
27
32
@@ -34,21 +39,35 @@ public API(IntPtr rm)
34
39
[ DllImport ( "Rainmeter.dll" , CharSet = CharSet . Unicode ) ]
35
40
private extern static IntPtr RmPathToAbsolute ( IntPtr rm , string relativePath ) ;
36
41
42
+ /// <summary>
43
+ /// Executes a command
44
+ /// </summary>
45
+ /// <param name="skin">Pointer to current skin (See API.GetSkin)</param>
46
+ /// <param name="command">Bang to execute</param>
47
+ /// <returns>No return type</returns>
48
+ /// <example>
49
+ /// <code>
50
+ /// [DllExport]
51
+ /// internal double Update(IntPtr data)
52
+ /// {
53
+ /// Measure measure = (Measure)data;
54
+ /// Rainmeter.API.Execute(measure->skin, "!SetVariable SomeVar 10"); // 'measure->skin' stored previously in the Initialize function
55
+ /// return 0.0;
56
+ /// }
57
+ /// </code>
58
+ /// </example>
37
59
[ DllImport ( "Rainmeter.dll" , EntryPoint = "RmExecute" , CharSet = CharSet . Unicode ) ]
38
60
public extern static void Execute ( IntPtr skin , string command ) ;
39
61
40
62
[ DllImport ( "Rainmeter.dll" ) ]
41
63
private extern static IntPtr RmGet ( IntPtr rm , RmGetType type ) ;
42
64
43
65
[ DllImport ( "Rainmeter.dll" , CharSet = CharSet . Unicode , CallingConvention = CallingConvention . Cdecl ) ]
44
- private extern static int LSLog ( LogType type , string unused , string message ) ;
66
+ private extern static int LSLog ( int type , string unused , string message ) ;
45
67
46
68
[ DllImport ( "Rainmeter.dll" , CharSet = CharSet . Unicode , CallingConvention = CallingConvention . StdCall ) ]
47
69
private extern static int RmLog ( IntPtr rm , LogType type , string message ) ;
48
70
49
- [ DllImport ( "Rainmeter.dll" , CharSet = CharSet . Unicode , CallingConvention = CallingConvention . Cdecl ) ]
50
- private extern static int RmLogF ( IntPtr rm , LogType type , string format , params string [ ] message ) ;
51
-
52
71
private enum RmGetType
53
72
{
54
73
MeasureName = 0 ,
@@ -75,10 +94,13 @@ public enum LogType
75
94
/// <returns>Returns the option value as a string</returns>
76
95
/// <example>
77
96
/// <code>
78
- /// internal void Reload(Rainmeter.API rm, ref double maxValue)
97
+ /// [DllExport]
98
+ /// public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
79
99
/// {
80
- /// string value = rm.ReadString("Value", "DefaultValue");
81
- /// string action = rm.ReadString("Action", "", false); // [MeasureNames] will be parsed/replaced when the action is executed with RmExecute
100
+ /// Measure measure = (Measure)data;
101
+ /// Rainmeter.API api = (Rainmeter.API)rm;
102
+ /// string value = api.ReadString("Value", "DefaultValue");
103
+ /// string action = api.ReadString("Action", "", false); // [MeasureNames] will be parsed/replaced when the action is executed with RmExecute
82
104
/// }
83
105
/// </code>
84
106
/// </example>
@@ -95,9 +117,12 @@ public string ReadString(string option, string defValue, bool replaceMeasures =
95
117
/// <returns>Returns the absolute path of the option value as a string</returns>
96
118
/// <example>
97
119
/// <code>
98
- /// internal void Reload(Rainmeter.API rm, ref double maxValue)
120
+ /// [DllExport]
121
+ /// public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
99
122
/// {
100
- /// string path = rm.ReadPath("MyPath", "C:\\");
123
+ /// Measure measure = (Measure)data;
124
+ /// Rainmeter.API api = (Rainmeter.API)rm;
125
+ /// string path = api.ReadPath("MyPath", "C:\\");
101
126
/// }
102
127
/// </code>
103
128
/// </example>
@@ -115,9 +140,12 @@ public string ReadPath(string option, string defValue)
115
140
/// <returns>Returns the option value as a double</returns>
116
141
/// <example>
117
142
/// <code>
118
- /// internal void Reload(Rainmeter.API rm, ref double maxValue)
143
+ /// [DllExport]
144
+ /// public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
119
145
/// {
120
- /// double value = rm.ReadDouble("Value", 20.0);
146
+ /// Measure measure = (Measure)data;
147
+ /// Rainmeter.API api = (Rainmeter.API)rm;
148
+ /// double value = api.ReadDouble("Value", 20.0);
121
149
/// }
122
150
/// </code>
123
151
/// </example>
@@ -135,9 +163,12 @@ public double ReadDouble(string option, double defValue)
135
163
/// <returns>Returns the option value as an integer</returns>
136
164
/// <example>
137
165
/// <code>
138
- /// internal void Reload(Rainmeter.API rm, ref double maxValue)
166
+ /// [DllExport]
167
+ /// public static void Reload(IntPtr data, IntPtr rm, ref double maxValue)
139
168
/// {
140
- /// int value = rm.ReadInt("Value", 20);
169
+ /// Measure measure = (Measure)data;
170
+ /// Rainmeter.API api = (Rainmeter.API)rm;
171
+ /// int value = api.ReadInt("Value", 20);
141
172
/// }
142
173
/// </code>
143
174
/// </example>
@@ -153,9 +184,11 @@ public int ReadInt(string option, int defValue)
153
184
/// <returns>Returns a string replacing any variables in the 'str'</returns>
154
185
/// <example>
155
186
/// <code>
156
- /// internal double Update()
187
+ /// [DllExport]
188
+ /// public static double Update(IntPtr data)
157
189
/// {
158
- /// string myVar = ReplaceVariables("#MyVar#").ToUpperInvariant();
190
+ /// Measure measure = (Measure)data;
191
+ /// string myVar = measure.api.ReplaceVariables("#MyVar#").ToUpperInvariant(); // 'measure.api' stored previously in the Initialize function
159
192
/// if (myVar == "SOMETHING") { return 1.0; }
160
193
/// return 0.0;
161
194
/// }
@@ -173,9 +206,13 @@ public string ReplaceVariables(string str)
173
206
/// <returns>Returns the current measure name as a string</returns>
174
207
/// <example>
175
208
/// <code>
176
- /// internal void Initialize(Rainmeter.API rm)
209
+ /// [DllExport]
210
+ /// public static void Initialize(ref IntPtr data, IntPtr rm)
177
211
/// {
178
- /// myName = GetMeasureName(); // declare 'myName' as a string in class scope
212
+ /// Measure measure = new Measure();
213
+ /// Rainmeter.API api = (Rainmeter.API)rm;
214
+ /// measure.myName = api.GetMeasureName(); // declare 'myName' as a string in measure class
215
+ /// data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
179
216
/// }
180
217
/// </code>
181
218
/// </example>
@@ -191,9 +228,13 @@ public string GetMeasureName()
191
228
/// <returns>Returns an IntPtr to the current skin</returns>
192
229
/// <example>
193
230
/// <code>
194
- /// internal void Initialize(Rainmeter.API rm)
231
+ /// [DllExport]
232
+ /// public static void Initialize(ref IntPtr data, IntPtr rm)
195
233
/// {
196
- /// mySkin = GetSkin(); // declare 'mySkin' as a IntPtr in class scope
234
+ /// Measure measure = new Measure();
235
+ /// Rainmeter.API api = (Rainmeter.API)rm;
236
+ /// measure.mySkin = api.GetSkin(); // declare 'mySkin' as a IntPtr in measure class
237
+ /// data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
197
238
/// }
198
239
/// </code>
199
240
/// </example>
@@ -203,21 +244,23 @@ public IntPtr GetSkin()
203
244
}
204
245
205
246
/// <summary>
206
- /// Retrieves a path to the Rainmeter data file (Rainmeter.data).
247
+ /// Retrieves a path to the Rainmeter data file (Rainmeter.data)
207
248
/// </summary>
208
249
/// <remarks>Call GetSettingsFile() in the Initialize function and store the results for later use</remarks>
209
250
/// <returns>Returns the path and filename of the Rainmeter data file as a string</returns>
210
251
/// <example>
211
252
/// <code>
212
- /// internal void Initialize(Rainmeter.API rm)
253
+ /// public static void Initialize(ref IntPtr data, IntPtr rm)
213
254
/// {
214
- /// if (rmDataFile == null) { rmDataFile = GetSettingsFile(); } // declare 'rmDataFile' as a string in global scope
255
+ /// data = GCHandle.ToIntPtr(GCHandle.Alloc(new Measure()));
256
+ /// Rainmeter.API api = (Rainmeter.API)rm;
257
+ /// if (rmDataFile == null) { rmDataFile = API.GetSettingsFile(); } // declare 'rmDataFile' as a string in global scope
215
258
/// }
216
259
/// </code>
217
260
/// </example>
218
- public string GetSettingsFile ( )
261
+ public static string GetSettingsFile ( )
219
262
{
220
- return Marshal . PtrToStringUni ( RmGet ( m_Rm , RmGetType . SettingsFile ) ) ;
263
+ return Marshal . PtrToStringUni ( RmGet ( IntPtr . Zero , RmGetType . SettingsFile ) ) ;
221
264
}
222
265
223
266
/// <summary>
@@ -227,9 +270,13 @@ public string GetSettingsFile()
227
270
/// <returns>Returns the path and filename of the skin as a string</returns>
228
271
/// <example>
229
272
/// <code>
230
- /// internal void Initialize(Rainmeter.API rm)
273
+ /// [DllExport]
274
+ /// public static void Initialize(ref IntPtr data, IntPtr rm)
231
275
/// {
232
- /// skinName = GetSkinName(); } // declare 'skinName' as a string in class scope
276
+ /// Measure measure = new Measure();
277
+ /// Rainmeter.API api = (Rainmeter.API)rm;
278
+ /// measure.skinName = api.GetSkinName(); } // declare 'skinName' as a string in measure class
279
+ /// data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
233
280
/// }
234
281
/// </code>
235
282
/// </example>
@@ -238,16 +285,41 @@ public string GetSkinName()
238
285
return Marshal . PtrToStringUni ( RmGet ( m_Rm , RmGetType . SkinName ) ) ;
239
286
}
240
287
288
+ /// <summary>
289
+ /// Executes a command auto getting the skin reference
290
+ /// </summary>
291
+ /// <param name="command">Bang to execute</param>
292
+ /// <returns>No return type</returns>
293
+ /// <example>
294
+ /// <code>
295
+ /// [DllExport]
296
+ /// public static double Update(IntPtr data)
297
+ /// {
298
+ /// Measure measure = (Measure)data;
299
+ /// measure.api.Execute("!SetVariable SomeVar 10"); // 'measure.api' stored previously in the Initialize function
300
+ /// return 0.0;
301
+ /// }
302
+ /// </code>
303
+ /// </example>
304
+ public void Execute ( string command )
305
+ {
306
+ Execute ( this . GetSkin ( ) , command ) ;
307
+ }
308
+
241
309
/// <summary>
242
310
/// Returns a pointer to the handle of the skin window (HWND)
243
311
/// </summary>
244
312
/// <remarks>Call GetSkinWindow() in the Initialize function and store the results for later use</remarks>
245
313
/// <returns>Returns a handle to the skin window as a IntPtr</returns>
246
314
/// <example>
247
315
/// <code>
316
+ /// [DllExport]
248
317
/// internal void Initialize(Rainmeter.API rm)
249
318
/// {
250
- /// skinWindow = GetSkinWindow(); } // declare 'skinWindow' as a IntPtr in class scope
319
+ /// Measure measure = new Measure();
320
+ /// Rainmeter.API api = (Rainmeter.API)rm;
321
+ /// measure.skinWindow = api.GetSkinWindow(); } // declare 'skinWindow' as a IntPtr in measure class
322
+ /// data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
251
323
/// }
252
324
/// </code>
253
325
/// </example>
@@ -257,9 +329,9 @@ public IntPtr GetSkinWindow()
257
329
}
258
330
259
331
/// <summary>
260
- /// DEPRECATED: Use Log(rm, type, message). Sends a message to the Rainmeter log.
332
+ /// DEPRECATED: Save your rm or api reference and use Log(rm, type, message). Sends a message to the Rainmeter log with no source .
261
333
/// </summary>
262
- public static void Log ( LogType type , string message )
334
+ public static void Log ( int type , string message )
263
335
{
264
336
LSLog ( type , null , message ) ;
265
337
}
@@ -268,40 +340,98 @@ public static void Log(LogType type, string message)
268
340
/// Sends a message to the Rainmeter log with source
269
341
/// </summary>
270
342
/// <remarks>LOG_DEBUG messages are logged only when Rainmeter is in debug mode</remarks>
271
- /// <param name="type">Log type (LOG_ERROR, LOG_WARNING, LOG_NOTICE, or LOG_DEBUG)</param>
343
+ /// <param name="rm">Pointer to the plugin measure</param>
344
+ /// <param name="type">Log type, use API.LogType enum (Error, Warning, Notice, or Debug)</param>
272
345
/// <param name="message">Message to be logged</param>
273
346
/// <returns>No return type</returns>
274
347
/// <example>
275
348
/// <code>
276
- /// Log(rm, LOG_NOTICE , "I am a 'notice' log message with a source");
349
+ /// Rainmeter.API. Log(rm, API.LogType.Notice , "I am a 'notice' log message with a source");
277
350
/// </code>
278
351
/// </example>
279
352
public static void Log ( IntPtr rm , LogType type , string message )
280
353
{
281
354
RmLog ( rm , type , message ) ;
282
355
}
283
356
357
+ /// <summary>
284
358
/// <summary>
285
359
/// Sends a formatted message to the Rainmeter log
286
360
/// </summary>
287
361
/// <remarks>LOG_DEBUG messages are logged only when Rainmeter is in debug mode</remarks>
288
362
/// <param name="rm">Pointer to the plugin measure</param>
289
- /// <param name="level ">Log level (LOG_ERROR, LOG_WARNING, LOG_NOTICE , or LOG_DEBUG )</param>
290
- /// <param name="format">Formatted message to be logged, follows printf syntax</param>
363
+ /// <param name="type ">Log type, use API.LogType enum (Error, Warning, Notice , or Debug )</param>
364
+ /// <param name="format">Formatted message to be logged, follows string.Format syntax</param>
291
365
/// <param name="args">Comma separated list of args referenced in the formatted message</param>
292
366
/// <returns>No return type</returns>
293
367
/// <example>
294
368
/// <code>
295
- /// string notice = "notice";
296
- /// LogF(rm, LOG_NOTICE, "I am a '%s' log message with a source", notice);
369
+ /// [DllExport]
370
+ /// public static double Update(IntPtr data)
371
+ /// {
372
+ /// Measure measure = (Measure)data;
373
+ /// string notice = "notice";
374
+ /// measure.api.LogF(measure.rm, API.LogType.Notice, "I am a '{0}' log message with a source", notice); // 'measure.rm' stored previously in the Initialize function
375
+ ///
376
+ /// return 0.0;
377
+ /// }
297
378
/// </code>
298
379
/// </example>
299
- public static void LogF ( IntPtr rm , LogType type , string format , params string [ ] args )
380
+ public static void LogF ( IntPtr rm , LogType type , string format , params Object [ ] args )
300
381
{
301
- RmLogF ( rm , type , format , args ) ;
382
+ RmLog ( rm , type , string . Format ( format , args ) ) ;
383
+ }
384
+
385
+ /// <summary>
386
+ /// Sends a message to the Rainmeter log with source
387
+ /// </summary>
388
+ /// <remarks>LOG_DEBUG messages are logged only when Rainmeter is in debug mode</remarks>
389
+ /// <param name="type">Log type, use API.LogType enum (Error, Warning, Notice, or Debug)</param>
390
+ /// <param name="message">Message to be logged</param>
391
+ /// <returns>No return type</returns>
392
+ /// <example>
393
+ /// <code>
394
+ /// [DllExport]
395
+ /// public static double Update(IntPtr data)
396
+ /// {
397
+ /// Measure measure = (Measure)data;
398
+ /// measure.api.Log(api, API.LogType.Notice, "I am a 'notice' log message with a source"); // 'measure.api' stored previously in the Initialize function
399
+ ///
400
+ /// return 0.0;
401
+ /// }
402
+ /// </code>
403
+ /// </example>
404
+ public void Log ( LogType type , string message )
405
+ {
406
+ RmLog ( this . m_Rm , type , message ) ;
302
407
}
303
- }
304
408
409
+ /// <summary>
410
+ /// Sends a formatted message to the Rainmeter log
411
+ /// </summary>
412
+ /// <remarks>LOG_DEBUG messages are logged only when Rainmeter is in debug mode</remarks>
413
+ /// <param name="type">Log type, use API.LogType enum (Error, Warning, Notice, or Debug)</param>
414
+ /// <param name="format">Formatted message to be logged, follows string.Format syntax</param>
415
+ /// <param name="args">Comma separated list of args referenced in the formatted message</param>
416
+ /// <returns>No return type</returns>
417
+ /// <example>
418
+ /// <code>
419
+ /// [DllExport]
420
+ /// public static double Update(IntPtr data)
421
+ /// {
422
+ /// Measure measure = (Measure)data;
423
+ /// string notice = "notice";
424
+ /// measure.api.LogF(API.LogType.Notice, "I am a '{0}' log message with a source", notice); // 'measure.api' stored previously in the Initialize function
425
+ ///
426
+ /// return 0.0;
427
+ /// }
428
+ /// </code>
429
+ /// </example>
430
+ public void LogF ( LogType type , string format , params Object [ ] args )
431
+ {
432
+ RmLog ( this . m_Rm , type , string . Format ( format , args ) ) ;
433
+ }
434
+ }
305
435
/// <summary>
306
436
/// Dummy attribute to mark method as exported for DllExporter.exe.
307
437
/// </summary>
@@ -310,6 +440,7 @@ public class DllExport : Attribute
310
440
{
311
441
public DllExport ( )
312
442
{
443
+
313
444
}
314
445
}
315
446
}
0 commit comments