MY PROBLEM:
I am trying to write a PowerShell script that refers to a Primary Interpo
Assembly that has been created using the tblimport utility. One of the
methods returns a COM interface that is decorated as [return:
MarshalAs(UnmanagedType.Interface)]
The complete disassembly of the method in the PIA using Reflector looks like
this:
[return: MarshalAs(UnmanagedType.Interface)]
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(0x60020000)]
public virtual extern IGalaxies QueryGalaxies([In, Optional,
MarshalAs(UnmanagedType.BStr)] string GRNodeName);
MY QUESTION:
Is it possible to call a method on the IGalaxies
(UnmanagedType.Interface) type in PowerShell?
Here is the disassembly of IGalaxies generated by Reflector:
[ComImport, Guid("00000010-6CBD-461A-9B7C-7A359A1A80E8"),
TypeLibType((short) 0x1040)]
public interface IGalaxies : IGalaxiesBase
{
[DispId(0)]
IGalaxy this[object galaxyIdentifier] { [return:
MarshalAs(UnmanagedType.Interface)]
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(0)] get; }
[DispId(0x60020001)]
int count { [MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), DispId(0x60020001)] get; }
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType="",
MarshalTypeRef=typeof(EnumeratorToEnumVariantMarshaler), MarshalCookie="")]
[MethodImpl(MethodImplOptions.InternalCall,
MethodCodeType=MethodCodeType.Runtime), TypeLibFunc((short) 0x40), DispId(-4)]
IEnumerator GetEnumerator();
}
THIS HOW FAR I GOT:
Here is what I tried to far using PowerShell (Script code and output):
[void][reflection.assembly]::LoadFrom("C

rogram FilesCommon
FilesArchestrAArchestrA.GRAccess.dll")
$GRA = new-object ArchestrA.GRAccess.GRAccessAppClass
$GRA.PSObject
Members : {CommandResult, License, QueryGalaxies, CreateGalaxy...}
Properties : {CommandResult, License}
Methods : {QueryGalaxies, CreateGalaxy, DeleteGalaxy,
get_CommandRe
sult...}
ImmediateBaseObject : ArchestrA.GRAccess.GRAccessAppClass
BaseObject : ArchestrA.GRAccess.GRAccessAppClass
TypeNames : {ArchestrA.GRAccess.GRAccessAppClass,
System.__ComObject,
System.MarshalByRefObject, System.Object}
$Galaxies = $GRA.QueryGalaxies("localhost")
$Galaxies.PSObject
Members : {GetLifetimeService, InitializeLifetimeService,
CreateObj
Ref, GetType...}
Properties : {}
Methods : {GetLifetimeService, InitializeLifetimeService,
CreateObj
Ref, GetType...}
ImmediateBaseObject : System.__ComObject
BaseObject : System.__ComObject
TypeNames : {System.__ComObject, System.MarshalByRefObject,
System.Ob
ject}
PS C

ocuments and SettingsStarfighter> $Galaxies.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False __ComObject
System.MarshalByR...
PS C

ocuments and SettingsStarfighter> $Galaxies.GetType().BaseType
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True MarshalByRefObject System.Object
--
Regards,
Klaus