.NET interop in PowerBuilder

旧时模样 提交于 2019-12-07 07:55:08

问题


I'm looking for a way to do two-way communication between a PB object and a .NET (C#) object. In looking at Brad's .NET version of his GUI controls, I see how to give the .NET object a reference to the PB object. But in that example, it's cast as a PowerObject (basically). That C# code only calls TriggerEvent() on the PB object.

I want to create a custom class in C# called foo1. I want to create a method on foo1 called bar1().

I want to create a custom class in PB called foo2. I want to create a method on foo2 called bar2().

I want to be able to create an instance of foo1 within foo2. I want to be able to call foo1.bar1() from within foo2.

(I'm good up until here.)

I want to be able to reference foo2 from within foo1. I want to be able to call foo2.bar2() from within foo1.


回答1:


I am sure there is a more eligent way to do this, but using COM might be the easiest.

  • Using COM in PowerBuilder
  • Using COM in .NET

Some people would say that COM is never the right answer, but I say use the right tool for the right job.




回答2:


I used the idea from here to create my C# control and it worked with it being called from PB and Qt.

Exposing Windows Form as ActiveX control

You may also want to look at P/Invoke




回答3:


PowerBuilder (version 6, 7 and 8.0) understand properly only BINARY contracts if you would like to connect objects written in different technologies. In reality it means COM objects with IDispatch interface (so called OleAutomation). It's the same kind of the objects that can be used by interpreted languages like VB6 or jscript (with wscript).

You don't have to deal with ConnectionPoints to have asynchronous communication between objects. Use your own regular interfaces.

Don't use Watcom C++ compiler to build any "proxy objects" - it was very weak compiler a few years ago. I was trying to compile and build some solution and it showed many internal errors during compilation. MS C++ compiler did the compilation without any problems.

Remember that your objects should be apartment compatible. PB uses only STA (Single Threaded Apartment). Please check it - maybe something has changed recently.



来源:https://stackoverflow.com/questions/842017/net-interop-in-powerbuilder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!