Page 1 of 1
VO and .net WPF interoperabiliy
Posted: Mon May 07, 2018 4:03 pm
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
VO and .net WPF interoperabiliy
Posted: Mon May 07, 2018 8:50 pm
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
VO and .net WPF interoperabiliy
Posted: Tue May 08, 2018 5:18 am
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
VO and .net WPF interoperabiliy
Posted: Tue May 08, 2018 8:01 am
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
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
VO and .net WPF interoperabiliy
Posted: Tue May 08, 2018 8:05 am
by wriedmann
Hi Nick,
thank you very, very much!
Wolfgang