Skip to content

Commit 1f26c87

Browse files
committed
Fixed examples in C# API
1 parent db4e6f9 commit 1f26c87

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

source/developers/plugins/csharp/index.html

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,24 @@ <h2 id="Optional">Optional functions</h2>
104104
<li><code>data</code> : Pointer to the data set in <a href="!plugin/csharp/#Initialize">Initialize</a>.</li>
105105
</ul>
106106
</p>
107-
<p><b>Returns</b>: The string value for the measure. If you want the number value (returned from <a href="!plugin/csharp/#Update">Update</a>) to be used as the measures value, return null instead. The return value must be marshalled.</p><br/>
108-
109-
<p>See: <a href="https://github.com/rainmeter/rainmeter-plugin-sdk/blob/3eb9d7fc911381cd82231ccc3b65be29635d82cc/C%23/PluginEmpty/PluginEmpty.cs#L81C25-L81C31">PluginEmpty code</a> for details.</p>
107+
<p><b>Returns</b>: The string value for the measure. If you want the number value (returned from <a href="!plugin/csharp/#Update">Update</a>) to be used as the measures value, return null instead. The return value must be marshalled.</p>
108+
<h3>Example:</h3>
109+
``` cs
110+
[DllExport]
111+
public static IntPtr GetString(IntPtr data)
112+
{
113+
Measure measure = (Measure)data;
114+
if (something)
115+
{
116+
// Return a string value to use for this measure (must be marshalled)
117+
return Rainmeter.StringBuffer.Update("SomeValue");
118+
}
110119

120+
// Return null when you want to use the number
121+
// value for this measure (the value returned from the Update function)
122+
return IntPtr.Zero;
123+
}
124+
```
111125
</dd>
112126
<dt id="ExecuteBang"><code>ExecuteBang</code> <small><code>void ExecuteBang(IntPtr data, string args)</code></small></dt>
113127
<dd>
@@ -140,8 +154,22 @@ <h3>Example:</h3>
140154
<li><code>argv</code> : Arguments passed to the function as an array of strings. <code>argv</code> is an array of strings (LPCWSTR) in C++ and must be marshalled to a C# style string.</li>
141155
</ul>
142156
</p>
143-
<p><b>Returns</b>: A string to replace the section variable with. If a null is returned, the variable will not be replaced and remain unchanged. The return value must be marshalled.</p><br/>
157+
<p><b>Returns</b>: A string to replace the section variable with. If a null is returned, the variable will not be replaced and remain unchanged. The return value must be marshalled.</p>
158+
<h3>Example:</h3>
159+
``` cs
160+
[DllExport]
161+
public static IntPtr ToLower(IntPtr data, const int argc,
162+
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)] const string[] argv)
163+
{
164+
Measure measure = (Measure)data;
165+
if (argc > 0)
166+
{
167+
// Do something and return a value to replace variable with (must be marshalled)
168+
return Rainmeter.StringBuffer.Update(doSomething(argv));
169+
}
144170

145-
<p>See: <a href="https://github.com/rainmeter/rainmeter-plugin-sdk/blob/3eb9d7fc911381cd82231ccc3b65be29635d82cc/C%23/PluginEmpty/PluginEmpty.cs#L81C25-L81C31">PluginEmpty code</a> for details.</p>
171+
return IntPtr.Zero; // Do not replace the variable
172+
}
173+
```
146174
</dd>
147-
</dl>
175+
</dl>

0 commit comments

Comments
 (0)