Groups | Blog | Home
all groups > dotnet interop > june 2005 >

dotnet interop : ROT


trinitypete
6/29/2005 2:43:06 AM
Hi all,

We use a Microsoft Business Solutions Application - Great Plains. This has a
proprietary language for development - Dexterity/Sanscript.

From Sanscript we can register a call back as an object on the ROT.

From C# I can get access to the running object (Marshal.GetActiveObject) but
can not execute any methods - no type information. The Sanscript support guys
in Fargo couldn't offer me any help apart from the following which is VB6
code passed through a .NET convertor. Can anyone help in how I can provide
type information for the object? I know its something to do with marshaling
the COM object but I cant work it out from documentation/web articles.

Heres the VB6 --> VB.NET code that was generated and worked although it also
seemed to object to missing type info.

Dim obj As Object
Dim i As String
Dim j As String
Dim x As String

i = "abc"
j = "xyz"

obj = GetObject( , "MARS.GenPOs2935")

'UPGRADE_WARNING: Couldn't resolve default property of object
obj.GeneratePurchaseOrders. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1037"'
x = obj.GeneratePurchaseOrders(i, j)

MsgBox(x & " " & i & " " & j)

'UPGRADE_NOTE: Object obj may not be destroyed until it is garbage
collected. Click for more:
'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"'
obj = Nothing

The "MARS.GenPOs2935" object is a dex object added using hte dex
COM_RegisterRunningObject() and successfully returned my dummy string back.

Thanks in advance.
trinitypete
7/4/2005 3:19:01 AM
OK No one relied but I managed to sort it out. Heres the code if any one is
interested in late binding to a running object with unknown type information
and unknown CLSID

using System.Runtime.InteropServices;
using System.Reflection;

//Let runtime discover type info for object by name
Type callbacktype = Type.GetTypeFromProgID("GreatPlains.Callback");
//Use interop to get objject off running object table - increases reference
count
object callback = Marshal.GetActiveObject("GreatPlains.Callback");
//Invoke the registered method
callbacktype.InvokeMember("DoSomething",BindingFlags.InvokeMethod,null,callback,null);//The
last null in the statement is an object array used for passing parameters to
the object/callback function
//Decrement the object reference count
Marshal.ReleaseComObject(callback);
//clear object references
callbacktype = null;
callback = null;


[quoted text, click to view]
AddThis Social Bookmark Button