R
Richard
Hi,
I am coding in C# and working with COM objects that were
written in Java. The product documentation for the Java
stuff states that the MS JVM does not support interface
inheritance - and then the documentation goes on to give
VB6 examples of how to get to a base interface given a
child interface.
Well I need to get to the base interface in C#! I have an
interface called "IPersistentObject" and it has a base
interface of "ISysObject". How can I get to ISysObject
given an instance of IPersistentObject? My code below
compiles but it's not working {pardon the spacing but the
newsgroup dooesn't do source code too well}:
{
IPersistentObject pobj = CreatePersistentObject();
ISysObject sysObj = (ISysObject)
Marshal.GetTypedObjectForIUnknown
(Marshal.GetIUnknownForObject(pobj), typeof(ISysObject));
IntPtr punk = Marshal.GetIUnknownForObject(sysObj);
sysObj.setObjectName("MyObject");
}
When this code runs "punk" reveals a non-zero value which
I'm taking to mean that in fact the QueryInterface did
succeed; the sysObj is an RCW that referes to something
that supports IUnknown. However when I try to use the
interface, to call "setObjectName", I get a
System.NullReference exception. Any ideas?
--Richard
I am coding in C# and working with COM objects that were
written in Java. The product documentation for the Java
stuff states that the MS JVM does not support interface
inheritance - and then the documentation goes on to give
VB6 examples of how to get to a base interface given a
child interface.
Well I need to get to the base interface in C#! I have an
interface called "IPersistentObject" and it has a base
interface of "ISysObject". How can I get to ISysObject
given an instance of IPersistentObject? My code below
compiles but it's not working {pardon the spacing but the
newsgroup dooesn't do source code too well}:
{
IPersistentObject pobj = CreatePersistentObject();
ISysObject sysObj = (ISysObject)
Marshal.GetTypedObjectForIUnknown
(Marshal.GetIUnknownForObject(pobj), typeof(ISysObject));
IntPtr punk = Marshal.GetIUnknownForObject(sysObj);
sysObj.setObjectName("MyObject");
}
When this code runs "punk" reveals a non-zero value which
I'm taking to mean that in fact the QueryInterface did
succeed; the sysObj is an RCW that referes to something
that supports IUnknown. However when I try to use the
interface, to call "setObjectName", I get a
System.NullReference exception. Any ideas?
--Richard