views:

347

answers:

3

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.

A: 

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

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

JasonRShaver
A: 

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.

Alex Stankiewicz
+1  A: 

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