Reputation: 472
I am trying to use the method DetachBuffer()
of Windows.Storage.Streams.DataWriter
but PowerShell only recognizes the IBuffer that it supposed to return as __ComObject
. I have used other WinRT objects successfully, but this one is giving me trouble.
[void][Windows.Storage.Streams.DataWriter, Windows.Storage.Streams, ContentType = WindowsRuntime]
$dataWriter = [Windows.Storage.Streams.DataWriter]::new()
$dataWriter.WriteByte(0x01)
$buffer = $dataWriter.DetachBuffer()
$buffer
System.__ComObject
$buffer | Get-Member
TypeName: System.__ComObject
Name MemberType Definition
---- ---------- ----------
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.Object InitializeLifetimeService()
ToString Method string ToString()
I am assuming that I need to "import" some WinRT class that DetachBuffer() is actually returning, but I have no clue what it is other than it implements IBuffer interface.
Upvotes: 5
Views: 398
Reputation: 48
In my search for an answer to a similar problem (IInputStream Interface) I came upon this Reddit thread that gets the content of IBuffer as follows:
[System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions].
GetMethod(
'ToArray',
[type[]]@([Windows.Storage.Streams.IBuffer])).
Invoke($null, @($buffer))
From your question it is unclear what you want to achieve, but let me know if this helps. If not, please amend the question so that it is clear what you want to do with the IBuffer.
As the commenter below correctly adds: PowerShell does not work with WinRT object that have no concrete type (in this case IBuffer Interface). I've been using .Invoke() to work around that, but in my very limited experience it's a hassle and not always gives you what you really need.
Upvotes: 1