5 Years later...

In the above discussion, the IStream object was created properly, but a variant type mismatch error would arise when attempting to invoke the COM method. I found some code in the DF Graphics Library utilizing IStream (CreateImageFromUCharArray/Releasestream in cGdiPlus.pkg) that pointed a way to a solution.

after creating the IStream object with the external function CreateStreamOnHGlobal, Changing the variant type to OLE_VT_DISPATCH using StoreDw fixed the issue. I am unsure why this is necessary.

Code:
    Procedure LoadUCharArray UChar[] ucaPdf
        Handle hoIStream
        Variant vStream
        Get CreateIStreamFromUcharArray ucaPdf to hoIStream
        Get pvComObject of hoIStream to vStream               
        Send ComLoadStream vStream
        Send ReleaseStream hoIStream
    End_Procedure

    {Visibility=Private}    Function CreateIStreamFromUcharArray UChar[] ucaData Returns Handle
        //Uchar -> OLE IStream Object  
        //Refer to: CreateImageFromUCharArray, ReleaseStream in cGDIPlus.pkg (DF Graphics Library)
        Variant hMem
        Handle hPdf
        Boolean bIsCreated
        Variant vStream vDoc
        Integer eResult iSize
        Address aMem aImage
        Handle hoIStream
        Handle pStream


        Move (SizeOfArray (ucaData)) to iSize
        If (iSize = 0) Procedure_Return
        Move (GlobalAlloc (GMEM_MOVEABLE ior GMEM_ZEROINIT, iSize)) to hMem
        If (hMem <> 0) Begin
            Move (GlobalLock (hMem)) to aMem
            Move (CopyMemory (aMem, AddressOf (ucaData), iSize)) to eResult
            Move (GlobalUnlock (hMem)) to eResult            
            
            Move 0 to pStream
            Move (Ole32_CreateStreamOnHGlobal (hMem, True, AddressOf(pStream))) to eResult            
            
            If (eResult = S_OK) Begin
                Move 0 to vStream                        
                Move (StoreDw (AddressOf (vStream), 0, OLE_VT_Dispatch)) to eResult //Change Type to VT_Dispatch
                Move (StoreDw (AddressOf (vStream), 8, pStream)) to eResult                                                            
                
                Get Create (RefClass(cComIStream)) to hoIStream
                Set pvComObject of hoIStream to vStream                          
                Get IsComObjectCreated of hoIStream to bIsCreated
            End
        End
        Function_Return hoIStream
    End_Function
Code:
External_Function Ole32_CreateStreamOnHGlobal "CreateStreamOnHGlobal" ole32.dll ;    Handle hGlobal ;
    Integer fDeleteOnRelease ;
    Pointer ppstm ;
    Returns Handle
The Code from the Com Object xpdfviewer

Code:
    // Load a PDF file from a stream    Procedure ComLoadStream Variant llstreamObj
        Handle hDispatchDriver
        Get phDispatchDriver to hDispatchDriver
        Send PrepareParams to hDispatchDriver 1
        Send DefineParam to hDispatchDriver OLE_VT_UNKNOWN llstreamObj
        Send InvokeComMethod to hDispatchDriver 63 OLE_VT_VOID
    End_Procedure

Quote Originally Posted by Nav Malhotra View Post
Hi,

I am trying to do two things.
1). Extract a PDF file from a zip file in memory.
This I was able to do by using inflate method from chilkat zip active X.The method returns a variant (byte array)

2).Load /View this PDF file from memory
We are using XpdfViewer from GlyphAndCog and it has a function called ComLoadStream which takes OLE Istream as an argument.


So i am stuck at how to convert the output from inflate method (i.e. byte array) into an IStream object.



Any ideas??


Thanks.
Nav.