According to the documentation of CreateStreamOnHGlobal , you use it. Quote:
The current contents of the memory block are unperturbed by the creation of a new thread object. Thus, you can use this function to open an existing stream in memory. The initial stream size is the size of the memory descriptor returned by the GlobalSize function.
Therefore, you must replace nBlockSize with 0 to allocate a zero-size buffer. Since the memory buffer must be movable, you also need to replace GMEM_FIXED with GMEM_MOVEABLE:
HGLOBAL gGlobal = GlobalAlloc(GMEM_MOVEABLE, 0);
After saving to the stream, the resulting size will be available as
size_t size = GlobalSize(hGlobal);
To access JPEG encoded data, you will need to use GlobalLock to get a pointer to the actual location in memory.
Note that global and local functions are deprecated and should no longer be used, but I donβt know the best implementation of IStream for your needs without going around the MSDN documentation. Maybe someone else can help here!
source share