• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

IStream determing size

Started by Edwin Knoppert, December 11, 2010, 01:11:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Edwin Knoppert

I have used your code for testing the istream interface since in my original (vtable) code i had some differences for determing the size of the data.
I wrote my code in the w95/w98 days and for some reason i subtracted #1 from the size, don't recall why but on XP and W7 it's incorrect.
Therefore i went back to basics by creating the code from scratch but under win98 i still get a difference.

I just need some conformation if this was only a matter for those older os's which are obsolete anyway.

Both the seek as size give a length of #8 instead of #5 (i run w98 in a virtual pc):


#Include "ObjIdl.inc"
#Include "OLE2UTILS.INC"
#Include "Ole2.inc"

Function PBMain() As Long

    Local hMem              As Long
    Local pMem              As Long
    Local hr                As Long
    Local ppstm             As IStream
    Local nLen_GetSize      As Quad
    Local nLen_Seek         As Quad
    Local libNewPosition    As Quad

    hMem = GlobalAlloc( %GMEM_MOVEABLE, 5 )
    pMem = GlobalLock( hMem )

    Poke$ pMem, "Hello"

    Call GlobalUnlock( hMem )

    hr = CreateStreamOnHGlobal( hMem, 0, ppstm )
   
    If hr <> %S_OK Then
        ? "Error"
        Exit Function
    End If

    nLen_GetSize = IStream_GetSize( ppstm )

    ppstm.Seek( 0, %STREAM_SEEK_SET, nLen_Seek )
    nLen_Seek = 0
    ppstm.Seek( 0, %STREAM_SEEK_END, nLen_Seek )

    ? Str$( nLen_GetSize ) & $CrLf & Str$( nLen_Seek )

End Function



Edwin Knoppert

The GlobalAlloc() may cause this trouble.
GlobalSize() returns the wrong size so i suspect IStream is using this call as well.
In the help it size this api may return a larger size which i can understand (common practise for memory allocators) however an IStream interface should be exact imo.

Edwin Knoppert

MSDN states the same and suggest you use SetSize()

After creating the interface set the size like:
ppstm.SetSize( 5 )

It now returns the correct size.

José Roca

 
I know nothing about Win 95/98. The first one I used was Windows 2000.

Edwin Knoppert

Doesn't matter, it seems by setting the desired size it is working fine.
Frankly i find it odd Windows nowadays creates memory with the exact size.
Maybe not but somehow stores the size (better) during creation.