C/C++ API Overview


This is an overview of the functions available in C/C++ SDK for Rainmeter.

RmReadString LPCWSTR ReadString(void* rm, LPCWSTR option, LPCWSTR defValue, BOOL replaceMeasures)

Returns a string representation of an option.

  • rm : Pointer to the plugin measure.
  • option : Option name to be read from the measure.
  • defValue : Default value for the option if it is not found or invalid.
  • replaceMeasures : If true, replaces section variables in the returned string. This argument is optional if using the C++ programming language, but is required if using the C programming language.

Example:

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
// The following will replace regular variables and
// section variables in the 'Value' option.
LPCWSTR value = RmReadString(rm, L"Value", L"DefaultValue");

// The following will only replace regular variables,
// but NOT section variables like [MeasureNames].
LPCWSTR action = RmReadString(rm, L"Action", L"", FALSE);
}
RmReadInt int RmReadInt(void* rm, LPCWSTR option, int defValue)

Retrieves the option defined in the skin file and converts it to an integer.

  • rm : Pointer to the plugin measure.
  • option : Option name to be read from the measure.
  • defValue : Default value for the option if it is not found, invalid, or a formula could not be parsed.

Example:

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
int value = RmReadInt(rm, L"Value", 20);
}
RmReadDouble double RmReadDouble(void* rm, LPCWSTR option, double defValue)

Retrieves the option defined in the skin file and converts it to a double type.

  • rm : Pointer to the plugin measure.
  • option : Option name to be read from the measure.
  • defValue : Default value for the option if it is not found, invalid, or a formula could not be parsed.

Example:

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
double value = RmReadDouble(rm, L"Value", 20.0);
}
RmReadPath LPCWSTR RmReadPath(void* rm, LPCWSTR option, LPCWSTR defValue)

Retrieves the option defined in the skin file and converts a relative path to a absolute path.

  • rm : Pointer to the plugin measure.
  • option : Option name to be read from the measure.
  • defValue : Default value for the option if it is not found or invalid.

Example:

PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
LPCWSTR path = RmReadPath(rm, L"MyPath", L"C:\\");
}
RmExecute void RmExecute(void* skin, LPCWSTR command)

Executes an action.

  • skin : Pointer to current skin (see RmGetSkin).
  • command : Action to execute.

Example:

PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;

// 'measure->skin' stored previously in the Initialize function
RmExecute(measure->skin, L"[!SetVariable SomeVar 10]");

return 0.0;
}
RmReplaceVariables LPCWSTR RmReplaceVariables(void* rm, LPCWSTR str)

Returns a string, replacing any variables (or section variables) within the inputted string.

  • rm : Pointer to the plugin measure.
  • str : String with unresolved variables.

Example:

PLUGIN_EXPORT double Update(void* data)
{
Measure* measure = (Measure*)data;

// 'measure->rm' stored previously in the Initialize function
LPCWSTR myVar = RmReplaceVariables(measure->rm, L"#MyVar#");

if (_wcsicmp(myVar, L"SOMETHING") == 0) { return 1.0; }
return 0.0;
}
RmGetMeasureName LPCWSTR RmGetMeasureName(void* rm)

Retrieves the name of the measure.

  • rm : Pointer to the plugin measure.

Example:

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;

// 'measure->myName' defined as a string (LPCWSTR) in 'Measure' class scope
measure->myName = RmGetMeasureName(rm);
}
RmGetSkin void* RmGetSkin(void* rm)

Retrieves an internal pointer to the current skin.

  • rm : Pointer to the plugin measure.

Example:

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;

// 'measure->mySkin' defined as a 'void*' in 'Measure' class scope
measure->mySkin = RmGetSkin(rm);
}
RmGetSkinName LPCWSTR RmGetSkinName(void* rm)

Retrieves full path and name of the skin.

  • rm : Pointer to the plugin measure.

Example:

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;

// 'measure->skinName' defined as a string (LPCWSTR) in the 'Measure' class scope
skinName = RmGetSkinName(rm);
}
RmGetSkinWindow HWND RmGetSkinWindow(void* rm)

Returns a pointer to the handle of the skin window.

  • rm : Pointer to the plugin measure.

Example:

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;

// 'measure->skinWindow' defined as HWND in 'Measure' class scope
measure->skinWindow = RmGetSkinWindow(rm);
}
RmGetSettingsFile LPCWSTR GetSettingsFile()

Retrieves a path to the Rainmeter data file (Rainmeter.data).

PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
Measure* measure = new Measure;
*data = measure;

// 'rmDataFile' defined as a string (LPCWSTR) in global scope
if (rmDataFile == nullptr) { rmDataFile = RmGetSettingsFile(); }
}
RmLog void RmLog(void* rm, int level, LPCWSTR message)

Sends a message to the Rainmeter log.

Example:

RmLog(rm, LOG_NOTICE, L"I am a 'notice' log message with a source");
RmLogF void RmLogF(void* rm, int level, LPCWSTR format, ...)

Sends a formatted message to the Rainmeter log.

Example:

std::wstring notice = L"notice";
RmLogF(rm, LOG_NOTICE, L"I am a '%s' log message with a source", notice.c_str());