fbpx
Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC: VO and .net WPF interoperabiliy

VO and .net WPF interoperabiliy 10 months 1 week ago #1

  • Oskar Atkinson
  • Oskar Atkinson's Avatar Topic Author
  • Offline
  • Posts: 1
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.

VO and .net WPF interoperabiliy 10 months 1 week ago #2

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.

VO and .net WPF interoperabiliy 10 months 1 week ago #3

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1401
  • Karma: 6
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
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

VO and .net WPF interoperabiliy 10 months 1 week ago #4

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.

VO and .net WPF interoperabiliy 10 months 1 week ago #5

  • wriedmann
  • wriedmann's Avatar
  • Away
  • Posts: 1401
  • Karma: 6
Hi Nick,

thank you very, very much!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

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

  • Page:
  • 1