VO and .net WPF interoperabiliy

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
Anonymous

VO and .net WPF interoperabiliy

Post by Anonymous »

Hi Nick,

per your request in this forum :-)

I know who to interface a .net win32 C# dll from VO using COM interop. ( That is how I am firing up the Crystal reports, modify a report using the RAS API and fire up the viewer)

Now I need to fire up a WPF view that has an user control on it. I assume it is going to work in a similar way, probably a bit different how to pass an window handle from VO and how to deal with it in
the WPF side

So, any hints or sample surely are welcome :-)

Thanks
Oskar
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

VO and .net WPF interoperabiliy

Post by NickFriend »

Hi Oskar (apologies, I put you as Oscar on the Google forum)

To call into a WPF app is very simple. On the WPF end it could be something like this (in pseudo-code)

Code: Select all

[ComVisible(true)]
public class WPFVOVisible
{
    private WindowInteropHelper _wih;
    private IntPtr _ownerHwnd;
    private Int32 _intvar;
    private string _stringvar;
    private WPFView _myview;

    public WPFVOVisible() { }

    public void StartWPFView(Int32 ownerHwnd, string param1, Int32 param2)
    {
        _ownerHwnd = (IntPtr)ownerHwnd;
        _stringvar = param1;
        _intvar = param2;

        try
        {
            _myview = new WPFView();
            _wih = new WindowInteropHelper(_myview);
            _wih.Owner = _ownerHwnd
            _myview.Show();
        }
        catch (Exception excep)
        {
            .....
        }
    }
}
Then on the VO end you could call it with

Code: Select all

oWPF:=OleAutoObject{"MyWPFProg.WPFVOVisible"}
IF oWPF:fInit
    oWPF:StartWPFView(SELF:Owner:Handle(),"a string",10)
ENDIF
The WindowsInteropHelper allows you to make the VO window the owner of the WPF window, so if you minimise the VO app, the WPF window will minimise automatically.

If you need to do callbacks into the VO app, let me know, I have code for that using delegates.

HTH

NIck
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

VO and .net WPF interoperabiliy

Post by wriedmann »

Hi Nick,

thank you very much, this is very interesting, and I'm pretty sure I will need that sometimes...

Could you show please also how to do the callback into the VO application?

TIA

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
NickFriend
Posts: 248
Joined: Fri Oct 14, 2016 7:09 am

VO and .net WPF interoperabiliy

Post by NickFriend »

Hi Wolfgang,

At the WPF end you need something like this (sending an int back to VO as a paramter)

Code: Select all

private delegate void VOFunctionDelegate([MarshalAs(UnmanagedType.I4)] Int32 param1);
private VOFunctionDelegate VOFunction;

public void Set_VOFunction_Callback(Int32 handle)
{
    VOFunction = (VOFunctionDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)handle, typeof(VOFunctionDelegate));
}
which you can then call simply as

Code: Select all

....
VOFunction(5);
....
At the VO end you need

Code: Select all

oWPF:Set_VOFunction_Callback(dword(_cast,@MyVOFunction()))

FUNCTION MyVOFunction(liParam AS LONGINT) AS VOID PASCAL
    .....
    RETURN
And that's it. Obviously you can register as many different functions as you need. I think the limitation is that it would be very difficult to callback into a class method in VO.

HTH

Nick
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

VO and .net WPF interoperabiliy

Post by wriedmann »

Hi Nick,

thank you very, very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply