It is currently February 25th, 2020, 8:32 am

Question about building plugins

Share and get help with Plugins and Addons
User avatar
Cariboudjan
Posts: 52
Joined: May 12th, 2019, 8:55 am

Question about building plugins

Post by Cariboudjan »

I'm not a programmer. I've scrapped together a C# .exe addon for Rainmeter based on a web tutorial I found on a blog. The addon works well, but I'd like to convert it into a .dll plugin for Rainmeter.

Is there a tutorial out there for building Rainmeter plugins?

The plugin uses the SystemInformation.WorkingArea Property to replace the depreciated DesktopWorkArea option built-into Rainmeter.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

There are no tutorials that I am aware of. The best advice I can give is here:

https://docs.rainmeter.net/developers/#CreatePlugin
https://docs.rainmeter.net/developers/plugin/csharp/
https://docs.rainmeter.net/developers/plugin/csharp/api/

The idea is to download the Rainmeter Plugin SDK, then be sure you can build and use the example plugins that come with it. Then use the PluginEmpty example as a starting point and add in your code. Build your plugin as either 32bit or 64bit depending on your system, and copy the .dll file to the Plugins folder in ..AppData\Roaming\Rainmeter\Plugins to test it.

This is going to assume that you are pretty familiar with coding in C++ or C#, and that you have a working knowledge of creating things in Microsoft Visual Studio. Statements like "I'm not a programmer" don't bode well for this... ;-)

I will say up front that I am not the person to help you with C# code, but if you have specific questions someone here may be able to help you.
User avatar
Cariboudjan
Posts: 52
Joined: May 12th, 2019, 8:55 am

Re: Question about building plugins

Post by Cariboudjan »

I have an extremely basic understanding of visual studio right now and C#, but possibly enough to take the code I've already repurposed with the exe and make a functional plugin. I'm looking at the example SDK right now, and I'm kind of scratching my head on where/how to insert the code into the example.
Last edited by Cariboudjan on December 28th, 2019, 1:18 pm, edited 2 times in total.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

Cariboudjan wrote:
December 28th, 2019, 1:15 pm
I have an extremely basic understanding of visual studio right now, but possibly enough to take the code I've already repurposed with the exe and make a functional plugin. I'm looking at the example SDK right now, and I'm kind of scratching my head on where/how to insert the code into the example.
That doesn't have a simple mouthfull of an answer really. Take a look at this C# plugin I did a while back and see if it helps:

https://github.com/jsmorley/PluginSpeech
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

Basically you want to define any global variables in class Measure, then in class Plugin you will have several functions

Initialize()
Where you do the kinds of things you do in the Initialize() function in Lua with Rainmeter. Things that only need to be done once. This is where you more or less "stand up" the plugin.

Reload()
Where you get options from the Measure you create in the skin, and do other things that don't need to happen on every update of the Measure.

Update()
Where you do all the "work". This is where you will create any number or string values the measure will return. This function will return the number value on each update of the Measure.

GetString()
This should be used to return any string values created in Update()

When the plugin measure is created (when the skin is loaded or refreshed) Initialize() and Reload() are executed. Reload() won't be executed again unless DyanmicVariables=1 is set on the measure, or !SetOption is used to dynamically change an option. On every update of the measure Update() is executed, and every time anything in Rainmeter "asks for" the string value of the measure GetString() is executed. This is why you do all the "work" in Update(), as GetString() can be called a ton of times on each update of the skin.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

Here is another example:

https://github.com/jsmorley/CheckNet
User avatar
Cariboudjan
Posts: 52
Joined: May 12th, 2019, 8:55 am

Re: Question about building plugins

Post by Cariboudjan »

I'm starting to understand what's happening here. I'm kind of poking at it right now.

So Update() is where I would put the functions, and initialize() is where I would call them?
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

Cariboudjan wrote:
December 28th, 2019, 2:05 pm
I'm starting to understand what's happening here. I'm kind of poking at it right now.

So Update() is where I would put the functions, and initialize() is where I would call them?
No, Initialize() is where you would do any work that is entirely static. That won't and can't change while the skin is running. Say for instance you wanted to collect the total amount of system memory available, or what version of Windows is running. That simply can't change, so you might want to do that in Initialize().

In Reload() you do things that you generally only want to do once when the skin is loaded or refreshed. The bonus to Reload() is that the work CAN be done again, if you change any option on the measure with !SetOption, or set DyanamicVariables=1 on the measure. This might be where you read all the options like MyNumber or MyString you set on the measure in the skin.

In Update() you do the "work". This is where you collect information from the system, fire off Windows API calls as needed, whatever. You create and return a single number value here, and create any string values that will be used by GetString.
User avatar
Cariboudjan
Posts: 52
Joined: May 12th, 2019, 8:55 am

Re: Question about building plugins

Post by Cariboudjan »

Alright. I think I'm starting to catch on. I can't seem to use System.Windows.Forms. Is this possible with a Rainmeter plugin? Or is there a setting somewhere I'm missing.
You do not have the required permissions to view the files attached to this post.
Last edited by Cariboudjan on December 28th, 2019, 2:33 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 20280
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Question about building plugins

Post by jsmorley »

Cariboudjan wrote:
December 28th, 2019, 2:31 pm
Alright. I think I'm starting to catch on. I can't seem to use System.Windows.Forms. Is this possible with a Rainmeter plugin? Or is there a setting somewhere I'm missing.
No, you cannot use forms with Rainmeter.