Results 1 to 3 of 3

Thread: I'd just like to confirm I'm doing this right

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2014
    Posts
    29

    Default I'd just like to confirm I'm doing this right

    I'm using a cImageContainer to display an image from memory, in a regular DF dialog.
    Everything seems to work, but I'm not quite clear if I have the stream functions working so as to avoid memory leaks.
    Code in question below:
    Code:
    //Assume that ucImage is a bitmap stored as a uChar[]
    //Assume this is running in an otherwise unmodified cImageContainer class
    //Note this is similar to procedure Read_Data in cDbImageContainer
    
    uChar[] ucImage
    Handle hImage
    pointer pImage pStream
    integer iRet
    //...... stuff happens....
    //etc
    //At this point, ucImage is populated
    Move (GlobalAlloc(GMEM_MOVABLE ior GMEM_ZEROINIT, (SizeOfArray(ucImage)) to hImage
    Move (GlobalLock(hImage)) to pImage
    Move (CopyMemory(pImage,(AddressOf(ucImage)),SizeOfArray(ucImage)) to iRet
    Move (GlobalUnlock(hImage)) to iREt
    Move 0 to pStream
    //This is what I'm concerned about:
    Move (Ole32_CreateStreamOnHGlobal(hImage,1,Addressof(pImage))) to iRet
    If (iRet = S_OK) begin
        Get CreateImageFromStream of hImage pStream to iRet
    //....etc
    According to the MSDN page for CreateStreamOnHGlobal, the "1" should cause the stream to free the global handle. But when does that happen?
    A value that indicates whether the underlying handle for this stream object should be automatically freed when the stream object is released. If set to FALSE, the caller must free the hGlobal after the final release. If set to TRUE, the final release will automatically free the hGlobal parameter.
    Does it happen when the DF object is destroyed? When the ImageContainer changes images?
    I'm especially not sure as the cDbImageContainer does appear to free the handle (if it exists, as it stores it in a property) as part of Read_Data, but wouldn't that do something like freeing the wrong handle/freeing the handle to an active IStream?
    As I said at the start, everything does appear to be working both with and without freeing the handle manually, I just wanted to make sure I was doing this correctly.

    Thanks.

  2. #2
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,869

    Default Re: I'd just like to confirm I'm doing this right

    Max,

    The code in the library is OK.
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  3. #3
    Join Date
    Jun 2014
    Posts
    29

    Default Re: I'd just like to confirm I'm doing this right

    All right, thanks. I appreciate the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •