PowerBuilder 11 and .NET: Callback function that passes foreign types to PowerBuilder

I'm using a C# assembly to catch COM events (using IConnectionPoint
etc) from a particular API.  But instead of handling the events
in .NET, I pass the information on back to PB so it simulates a type
of callback.  It seems to work, but I don't know for how long.
This is the one the events that gets raised.  The _notifyItemMethod is
the name of the method on the PowerBuilder object.  The _pbSession is
obtained from the .Session property of the PowerBuilder object that I
pass to the constructor of the event handler.
        public void NtfyItem(string oper, int flags, IEOM_Object
father, IEOM_Object dep)
            if (_pbSession != null && !
                PBArgument operArg = new PBArgument();
                operArg.ParameterType = typeof(string);
                operArg.Style = ParameterStyle.ByValue;
                operArg.Value = new PBString(oper);
                PBArgument flagsArg = new PBArgument();
                flagsArg.ParameterType = typeof(int);
                flagsArg.Style = ParameterStyle.ByValue;
                flagsArg.Value = new PBInt(flags);
                PBArgument fatherArg = new PBArgument();
                fatherArg.ParameterType = typeof(IEOM_Object);
                fatherArg.Style = ParameterStyle.ByValue;
                fatherArg.Value = new PBOleObject(father);
                PBArgument depArg = new PBArgument();
                depArg.ParameterType = typeof(IEOM_Object);
                depArg.Style = ParameterStyle.ByValue;
                depArg.Value = new PBOleObject(dep);
                _pbSession.PostMethod(_pbObject, _notifyItemMethod,
                    new PBArgument[] { operArg, flagsArg, fatherArg,
depArg, });
The problem is though that I can't seem to use the values in the
"father" and "dep" parameters in PowerBuilder.  They exist, and I can
call some of the methods on there without crashing the application,
but I never get a valid result.  I've confirmed that PowerBuilder does
indeed recognize the method names because if I enter names that don't
exist I get the "Name not found calling..." error.
This is the code in my PowerBuilder application:
public subroutine uf_notifyitem (string as_operation, integer
ai_flags, oleobject aole_container, oleobject aole_object);
String ls_ItemStatus = "Unknown"
OleObject lole_status, lole_ObjectInfo
// lole_ObjectInfo is always null after this operation.  It shouldn't
// It also returns null with methods that return "string"
lole_ObjectInfo = aole_object.get_object_info()
// This line crashes
lole_status = lole_ObjectInfo.status_info
ls_ItemStatus = lole_status.name
mle_results.Text += as_operation + ": " +  "(" + ls_ItemStatus + ")" +
end subroutine
Forgive me if my formatting is a bit off...
2/21/2008 5:40:59 PM
📁 sybase.powerbuilder.general
📃 62418 articles.

💬 1 Replies

I managed to figure it out.
Instead of passing the values back to PB as PBOleObject, I pass them
back as PBAny variables
Then, in PB I've got the following code:
#if defined PBWINFORM then
        System.Object l_intermediary
        EOMComLib.IEOM_Object l_objectInterface
        EOMComLib._EOM_ObjectInfo l_objectInfo
        // "Cast" the any variable into a System.Object - we cast directly
        l_intermediary = aole_object
        // "Recast" into the form we want
        l_objectInterface = l_intermediary
        // Get the object information
        l_objectInfo = l_objectInterface.get_object_info()
        // Save the status information for display
        ls_ItemStatus = objectInfo.status_info.name
#end if
2/22/2008 2:21:12 PM