It is currently March 28th, 2024, 8:43 pm

Debugging a plugin

Get help with creating, editing & fixing problems with skins
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Debugging a plugin

Post by chilio »

balala wrote:I don't know if this will help, but have you seen this: https://docs.rainmeter.net/developers/#CreatePlugin?
Jup, that's where I got the empty plugin (you pointed me there before ;)
It got me quite far, but now I'm facing a brick wall again ^^'
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Debugging a plugin

Post by balala »

Although I wrote once a plugin and had a few attempts on writing a few others, I have no experience in working with C (nor with C++, nor in C#), so here someone else will have to help you. I'm sorry...
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Debugging a plugin

Post by SilverAzide »

chilio wrote:Anyone out here with experience building plugins?
Sure... Not sure why you are having an error, but you can use the SDK to build the "Empty" plug-in and try that.

Try using this PluginEmpty.cs. I've added the logging code in there for you.

Code: Select all

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Rainmeter;

// Overview: This is a blank canvas on which to build your plugin.

// Note: GetString, ExecuteBang and an unnamed function for use as a section variable
// have been commented out. If you need GetString, ExecuteBang, and/or section variables 
// and you have read what they are used for from the SDK docs, uncomment the function(s)
// and/or add a function name to use for the section variable function(s). 
// Otherwise leave them commented out (or get rid of them)!

namespace PluginEmpty {
  class Measure {
    public Rainmeter.API Api;

    static public implicit operator Measure(IntPtr data) {
      return (Measure) GCHandle.FromIntPtr(data).Target;
    }
  }

  public class Plugin {
    [DllExport]
    public static void Initialize(ref IntPtr data, IntPtr rm) {

      Measure measure = new Measure();
      measure.Api = (Rainmeter.API) rm;

      measure.Api.Log(API.LogType.Notice, "Initialize fired");

      data = GCHandle.ToIntPtr(GCHandle.Alloc(measure));
    }

    [DllExport]
    public static void Finalize(IntPtr data) {
      GCHandle.FromIntPtr(data).Free();
    }

    [DllExport]
    public static void Reload(IntPtr data, IntPtr rm, ref double maxValue) {
      Measure measure = (Measure) data;

      measure.Api.Log(API.LogType.Notice, "Reload fired");
    }

    [DllExport]
    public static double Update(IntPtr data) {
      Measure measure = (Measure) data;
      measure.Api.Log(API.LogType.Notice, "Update fired");

      return 0.0;
    }
  }
}
PluginEmpty.jpg
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Debugging a plugin

Post by chilio »

SilverAzide wrote: Sure... Not sure why you are having an error, but you can use the SDK to build the "Empty" plug-in and try that.

Try using this PluginEmpty.cs. I've added the logging code in there for you.
Finally a bit of time after a busy weekend, tried your solution but it didn't help :(
I put your code inside pluginEmpty.cs, build it in release mode, copied it to the plugins folder and it had the exact same result: file in use, but nothing logged.
Here is my skin if that helps a bit:

Code: Select all

[Variables]
FolderPath = "C:\Users\Reus\Pictures\Wallpapers"
IncludeSubFolders = 1
Interval = 1
Width = 800
Height = 800

[Rainmeter]
Update=5000

;--------------------------------------------
[Metadata]
Name=Custom Slideshow Frame
Author=M4he
Information=Highly customizable picture frame with subtle drop shadow that displays a picture slideshow of a specific folder. Please edit the skin for customization!
Version=1.0

;--------------------------------------------
[MeasureImage]
Measure=Plugin
Plugin=Plugins\QuotePlugin.dll
PathName=#FolderPath#
Subfolders=#IncludeSubFolders#
FileFilter=*.jpg;*.jpeg;*.png;*.bmp
UpdateDivider=#Interval#


;--------------------------------------------
[pluginMeasure]
Measure = plugin
plugin = Empty

[Image]
Meter=IMAGE
MeasureName=MeasureImage
PreserveAspectRatio=1
X = 0
Y = 0
W = #Width#
H = #Height#
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Debugging a plugin

Post by chilio »

Does anyone have other ideas?
Should I try to re-install rainmeter?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Debugging a plugin

Post by balala »

chilio wrote:Should I try to re-install rainmeter?
Don't think this would help. Usually it never does.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2588
Joined: March 23rd, 2015, 5:26 pm

Re: Debugging a plugin

Post by SilverAzide »

chilio wrote:Does anyone have other ideas?
Should I try to re-install rainmeter?
No, this is a waste of time as noted. You are doing something fundamentally wrong, and unfortunately from your descriptions I cannot tell what it is. The code I posted definitely works and -- in fact -- the code you posted should have worked too.

Install the skin below, it has the Empty plugin using the code I posted above. Make sure you tell the installer to overwrite your Empty.dll plugin so it will use this one. Open the Rainmeter About window (Log tab), then load the EmptyTester skin; all it does is display a tiny window saying "hello world". What you should see in the About window is the Initialization and Reload events fire, followed by the Update events firing at 1 second intervals (as shown in the screenshot above).
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
User avatar
tjhrulz
Developer
Posts: 267
Joined: October 13th, 2016, 1:28 am
Location: Earth

Re: Debugging a plugin

Post by tjhrulz »

Edit: Looking through it all since the file is locked it is likely working right, try building in debug and see if when you attach VS to Rainmeter if it says symbols have been loaded when you add a breakpoint. If I had to guess you are copying the wrong .dll that is before it was dllexported (Dont worry I do it all the time). Try either copying the .dll found somewhere else in your build directory or using my postbuild stuff I posted down below and see if that works.
Also you are free to try any of my plugins and see if they work if the above does not help, quickest way to force a log output out of one would be to load GPMDPPlugin into a measure with options defined and it should yell at you. (My apologies for the horrible layout of the code in advance) https://github.com/tjhrulz/GPMDP-Plugin


Sorry I just showed up so if I covered something someone else has my bad, how are you debugging it? Remember you will need to copy the plugin to the %appdata%/Rainmeter/plugins folder. (I really need to get around to making a video series on how to best get started building plugins)


Most of the time when I am debugging I like to have visual studio attached so I can go line by line in my plugin. So typically I will have Visual Studio start Rainmeter for me. For C# you can do this by going to under your toolbar Project>Properties>Debug>Start External Program and enter the path to Rainmeter.

I also like to have a post build event to taskkill Rainmeter, export the .DLL for me, and the copy it to the Rainmeter plugins folder.

The one I use on every project is

Code: Select all

taskkill /f /fi "imagename eq Rainmeter.exe"
"$(SolutionDir)API\DllExporter.exe" "$(ConfigurationName)" "$(PlatformName)" "$(TargetDir)\" "$(TargetFileName)"
xcopy  "$(TargetDir)$(TargetFileName)" "%appdata%\Rainmeter\Plugins" /Y
That will kill rainmeter but not error if it is not running and will copy and overwrite. You may need to tweak some of it if your project layout is different but if you are using the empty one it will be the same.

If you set it up like that then you can just build in debug, set a breakpoint, hit run, and be good to go and hit that point. Then there is no need to put a API log in there to test if it is running.

Oh also dont forget you need to load a skin that has a measure for your plugin, something like this would work fine and display the string value of the measure for you too. Just change out Plugin=NAMEOFDLLGOESHERE to whatever the name of the .dll file you export is (So the empty plugin would be PluginEmpty)

Code: Select all

[Rainmeter]
Update=1000
BackgroundMode=2
SolidColor=255, 255, 255, 255

[TestMeasure]
Measure=Plugin
Plugin=NAMEOFDLLGOESHERE

[TestMeter]
Meter=String
MeasureName=TestMeasure
X=0
Y=0
W=200
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Debugging a plugin

Post by chilio »

SilverAzide wrote:No, this is a waste of time as noted. You are doing something fundamentally wrong, and unfortunately from your descriptions I cannot tell what it is. The code I posted definitely works and -- in fact -- the code you posted should have worked too.

Install the skin below, it has the Empty plugin using the code I posted above. Make sure you tell the installer to overwrite your Empty.dll plugin so it will use this one. Open the Rainmeter About window (Log tab), then load the EmptyTester skin; all it does is display a tiny window saying "hello world". What you should see in the About window is the Initialization and Reload events fire, followed by the Update events firing at 1 second intervals (as shown in the screenshot above).
Fixed it! =D
I needed to update to the beta version to run your skin. After upgrading, your skin worked, and so did mine =D
Maybe the re-install did something afterall?
chilio
Posts: 48
Joined: January 26th, 2018, 9:56 am

Re: Debugging a plugin

Post by chilio »

tjhrulz wrote: If you set it up like that then you can just build in debug, set a breakpoint, hit run, and be good to go and hit that point. Then there is no need to put a API log in there to test if it is running.
OMG THIS IS ACTUALLY POSSIBLE?!! :o :jawdrop :o

I will try to do this, but I will probably need a lot of help ^^'