fbpx
× Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET

VO and .net WPF interoperabiliy

More
8 months 2 weeks ago #1 by Oskar Atkinson
VO and .net WPF interoperabiliy was created by Oskar Atkinson
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

Please Log in or Create an account to join the conversation.

More
8 months 2 weeks ago #2 by Nick Friend
Replied by Nick Friend on topic VO and .net WPF interoperabiliy
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)
[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
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

Please Log in or Create an account to join the conversation.

More
8 months 2 weeks ago #3 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic VO and .net WPF interoperabiliy
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

Please Log in or Create an account to join the conversation.

More
8 months 2 weeks ago #4 by Nick Friend
Replied by Nick Friend on topic VO and .net WPF interoperabiliy
Hi Wolfgang,

At the WPF end you need something like this (sending an int back to VO as a paramter)
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
....
VOFunction(5);
....

At the VO end you need
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

Please Log in or Create an account to join the conversation.

More
8 months 2 weeks ago #5 by Wolfgang Riedmann
Replied by Wolfgang Riedmann on topic VO and .net WPF interoperabiliy
Hi Nick,

thank you very, very much!

Wolfgang

Please Log in or Create an account to join the conversation.