I should test using Hydra to use a .NET component (as plugin) in a Delphi app (as host). The first step was easy, only to get the component visible and usable for itself.
But the main part is to make a object in the plugin (.NET) usable from the host (Delphi). I found the article “How to pass objects”, but I’m confused on it and cannot get it work. Especially because it says in the beginning it would describe marshaling in both directions, but in the section “Putting All Together” there is only .NET host und Delphi plugin.
Is there a complete sample project available for marshaling a object?
I’m using: Visual Studio 2013, Delphi XE8, RemObjects Hydra 4.0.77.1109
Hello
Please take a look at this article too: http://wiki.remobjects.com/wiki/Passing_interfaces_between_Host_and_Plugins
It describes marshalling more detailed and mentions a sample (Delphi WPF) you are interested in.
Regards
Thanks for the hint.
I tried to step through the article and create the code fragments into a working app. The first part (Custom interfaces basics) works fine. But on the second part (Data marshaling) I have stopped with a lot of question marks in my head. I have absolute no idea, how to get it in a working source code. The title is “Arrays”, but the source line shows a function with the return type byte[], not a variable. The text above includes “Our converter tool…”, which tool?
The same text is on the page “How to pass arrays”, “…our converter (described above)…” and “Our converter tool…”.
Hello
The converter can be found in RAD Studio’s menu at Hydra → Import Interfaces from .NET assemblies
byte[] is an array of bytes in .NET.
Here is a simplified real-world example of data processing approach (it is Delphi plugin → .NET host but you should see the general idea).
We need to retrieve a list of DriverInfo data objects from Delphi plugin.
Structure interfaces at Delphi side are defined as
IPlugin = interface (IDispatch)
['{744DDD40-EDEE-468D-88E6-5EFCFD21C48B}']
end;
IDriverInfo = interface(IPlugin)
['{b2fc94f8-7152-48fa-b3a2-e0c560036a48}']
function get_Name: WideString; safecall;
procedure set_Name(const value: WideString); safecall;
function get_DisplayName: WideString; safecall;
procedure set_DisplayName(const value: WideString); safecall;
// Skipped a lot of property getter/setter methods
property Name: WideString read get_Name write set_Name;
property DisplayName: WideString read get_DisplayName write set_DisplayName;
// Skipped a lot of property definitions
end;
IDriverManager = interface(IPlugin)
['{EE5C8204-4DD7-49F1-836C-CDD652431590}']
function GetAvailableDrivers: PVarArray{IDriverInfo}; safecall;
end;
The .NET counterside looks like (Oxygene .NET code, C# one would be very similar)
[System.Runtime.InteropServices.Guid('744DDD40-EDEE-468D-88E6-5EFCFD21C48B')]
IPlugin = public interface
end;
[System.Runtime.InteropServices.Guid('B2FC94F8-7152-48FA-B3A2-E0C560036A48')]
IDriverInfo = public interface(IPlugin)
property Name: String read write;
property DisplayName: String read write;
//Properties skipped
end;
[System.Runtime.InteropServices.Guid('58189BC8-347B-4F10-9FB7-70BD528C6DC0')]
IConnectionInformation = public interface(IPlugin)
method GetAvailableDrivers(): array of IDriverInfo;
end;
Hope that helps
Sorry, but I didn’t think it helps really, anyway I try it.
Ok, the “converter tool” is now clear. But the text says, that this tool converts something like this “byte[] GetBytes();” to that “function GetBytes: PVarArray{Byte}; safecall;”. I think a lot is still missing. In my understanding the tool only converts interfaces, the text contains no interfaces. I suspect the function has to be part of an interface.
Hello
Maybe it will be better if you’ll send the sample project to support@ ? In that case we’ll be able to see which exactly next step is missing.
By ‘sample’ here I mean a .NET plugin + Delphi host projects (preferable simple ones) that you try to connect.
Thanks in advance
To my surprise, I get it worked!
Not only the array (my assumption was right). Also the object marshaling from “How to pass objects”. But it was a really hard and time consuming job to get the code fragments into a working host and plugin.
I think some small examples would have made it easier for beginners like me. Additional to the howtos in the wiki. Only a suggestion.
Anyway, at the moment I think it is not usable for me. It takes too long to implement the marshaling for this really extensive class. A generator or something like this would be very helpful.