The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Powga (1) [Avatar] Offline
#1
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("Csmilierogram 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 Csmilieocuments and SettingsStarfighter> $Galaxies.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False __ComObject
System.MarshalByR...

PS Csmilieocuments and SettingsStarfighter> $Galaxies.GetType().BaseType

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True MarshalByRefObject System.Object


--
Regards,

Klaus