What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Custom sensor using a C++ Dll

Votes:

0

Hello, I need to write a custom dll sensor using C++. I am basing it on the documentation here:

https://www.paessler.com/manuals/prtg/custom_sensors#interface_dll

I am having trouble getting it to work with PRTG. PRTG can call the sensor and extract the message, but it says the sensor is 'down' and cannot read the value. This is the code in my header file that exposes the function:

extern "C" PRTGWrapper_API int perform(char* para, char*  msg);

And this is the code in the cpp file:

using namespace std;


int perform(char* para, char* msg)
{
	try
	{

		const char* str = u8"3:Test\0";

		memcpy(msg, str, sizeof(char) * 7);
		

		return 0x0;
	}
	catch (const std::exception& e)
	{		
		return 0x2;
	}
}

When I add this as a custom exe/dll sensor I can see the message "Test" underneath the sensor name, which implies that the code must be running. However each call results in an error and I cannot see the value.

Has anyone got an example of this in C++, or even in another unmanaged language like Delphi? Thanks

custom-sensor dll prtg

Created on Oct 22, 2020 9:23:10 AM

Last change on Oct 23, 2020 4:57:37 AM by  Marijan Horsky [Paessler Support]



1 Reply

Votes:

0

It looks like this is a mismatch of the calling conventions which results in a crash at the end of the runtime of the component, that loads the dll.

extern "C" PRTGWrapper_API int __stdcall perform(char* para, char* msg);
#pragma comment(linker, "/EXPORT:perform=_perform@8")

​ int __stdcall perform(char* para, char* msg) { try { const char* str = u8"3:Test\0"; memcpy(msg, str, sizeof(char) * 7); return 0x0; } catch (const std::exception& e) { return 0x2; } } will work.

Created on Oct 27, 2020 6:23:50 PM by  Mathias Hengl [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.