Is it possible to pass a structure through an interface to a plugin?

fatron

Member
Joined
May 13, 2010
Messages
18
Programming Experience
1-3
I'm working on a project where I'm experimenting with building and implementing plugins. I have a structure called "sensor" in the plugin that contains several elements. I would like to be able to return that structure to my main program through the interface, but it doesn't work, and google hasn't been very helpful (probably because I'm searching for the wrong terms). The plugin works fine if I'm passing strings or other variable types, but when I switch from strings to my structure, I get a couple of errors. On my main form where I try to call the function, I get the error 'value of type iMyPlugin.sensor cannot be converted to frmMain.sensor'. In the plugin code, I get the error 'GetSensorReading cannot implement GetSensorReading because there is no matching function on the interface'.
Is what I want to do possible, or is there a better way to do what I want?

This is roughly the code I'm using.
In my main program, I've defined a structure
VB.NET:
structure Sensor
    dim RawReading as string
    dim NumericReading as double
end structure

I call the function in the plugin that returns information like this:
VB.NET:
dim tempSensor as sensor
tempsensor = sensorPlugin.GetSensorReading

In my plugin interface, I've defined the structure again, plus added the line to to interface with the plugin.
VB.NET:
public interface iMyPlugIn
structure sensor
    dim RawReading as string
    dim NumericReading as double
end structure

function GetSensorReading() as sensor

End Interface

In the code of my plugin, I define sensor again, and also have the code for the GetSensorReading Function
VB.NET:
structure sensor
    dim RawReading as string
    dim NumericReading as double
end structure

public function GetSensorReading() as sensor implements PluginInterFace.IMyPlguin.GetSensorReading
dim temp as sensor
temp.rawreading = "test"
temp.NumericReading = 1.1
return temp
end function

Any help is appreciated.
 
As error explains type iMyPlugin.Sensor is different to type frmMain.Sensor, both have to use the common iMyPlugin.Sensor type, being available in a class library both reference. You don't define this type again in other projects.
 
Thanks. That seems to work. I made a new class and added the reference to that class to my plugin, interface, and main project.

Code is like this:
VB.NET:
Namespace CustomDataTypes
    Public Class Sensor
        public RawReading as string
        public NumericReading as double
    End Class
End Namespace
 
Back
Top