twain/twain-samples

[Bug] Native transfer DIB handle doesn't respect GlobalLock call [sf#31]

Closed this issue · 2 comments

Reported by michalzaganczyk on 2011-11-02 09:15 UTC
It seems that the DIB allocated by the sample data source in native transfer mode is allocated with GPTR flag. The result is that the DIB lock count returned by GlobalFlags(hDIB) is always 0, regardless of GlobalLock(hDIB) calls.

GPTR flag is a combination of GMEM_FIXED and GMEM_ZEROINIT. This makes the GlobalLock calls is pointless on the DIB handle, because for memory allocated with these flags, GlobalFlags function always returns 0, what makes lock count checking impossible.

This can lead to errors in software which relies on tracking of the DIB's lock count (ie. the asynchronous DIB processing in other thread).

I think the bug is here (src/DSMInterface.cpp, lines 215-230):

//////////////////////////////////////////////////////////////////////////////
// The following functions are defined in the DSM2,
// For backwards compatibiltiy on windows call the default function
TW_HANDLE _DSM_Alloc(TW_UINT32 _size)
{
if(g_DSM_Entry.DSM_MemAllocate)
{
return g_DSM_Entry.DSM_MemAllocate(_size);
}

#ifdef TWH_CMP_MSC
return ::GlobalAlloc(GPTR, _size); /* ========== GPTR IS SET HERE ========== */
#endif

return 0;
}

Commented by mihailm on 2016-02-24 15:47 UTC
This is is done for speed purpose.

Updated by mihailm on 2016-02-24 15:47 UTC

  • status: open --> wont-fix
  • Group: --> Application CMD