Home › Forums › TWAIN Classic › DS problem when CAP_SUPPORTEDCAPS
- This topic has 3 replies, 2 voices, and was last updated 13 years, 7 months ago by MSM.
- AuthorPosts
It can’t work under TWAIN2 Sample App. Can anyone tell me why? Thanks.
//g_DSM_Entry is import from DAT_ENTRYPOINT
case CAP_SUPPORTEDCAPS:
{
TW_ARRAY *array;
TW_UINT16 ItemCount=2;
pCap->ConType=TWON_ARRAY;
if(g_DSM_Entry.DSM_MemAllocate!=0)
{
pCap->hContainer=g_DSM_Entry.DSM_MemAllocate(sizeof(*array)+sizeof(TW_UINT16)*(ItemCount)-sizeof(TW_UINT8));
}
else
{
pCap->hContainer=GlobalAlloc(GHND,sizeof(*array)+sizeof(TW_UINT16)*(ItemCount)-sizeof(TW_UINT8));
}
if(pCap->hContainer)
{
if(g_DSM_Entry.DSM_MemLock!=0)
{
array=(TW_ARRAY*)g_DSM_Entry.DSM_MemLock(pCap->hContainer);
}
else
{
array=(TW_ARRAY*)GlobalLock(pCap->hContainer);
}
array->ItemType=TWTY_UINT16;
array->NumItems=ItemCount;
array->ItemList[0]=CAP_SUPPORTEDCAPS;
array->ItemList[1]=CAP_XFERCOUNT;
if(g_DSM_Entry.DSM_MemUnlock!=0)
{
g_DSM_Entry.DSM_MemUnlock(pCap->hContainer);
}
else
{
GlobalUnlock(pCap->hContainer);
}
}
else
{
m_IndependantCapMap.m_DSConditionCode=TWCC_LOWMEMORY;
twrc=TWRC_FAILURE;
}
break;
}
Hi Gregary,
see declaration of TW_ARRAY:
typedef struct {
TW_UINT16 ItemType;
TW_UINT32 NumItems; /* How many items in ItemList */
TW_UINT8 ItemList[1]; /* Array of ItemType values starts here */
} TW_ARRAY, FAR * pTW_ARRAY;ItemList is a TW_UINT8, but not TWTY_UINT16.
You have to fill array properly.TWTY_UINT16 *p_un16Array = (TWTY_UINT16 *)array->ItemList;
p_un16Array[0]=CAP_SUPPORTEDCAPS;
p_un16Array[1]=CAP_XFERCOUNT;Thanks for your response.
I change my code like this:
((TW_UINT16*)array->ItemList)[0]=CAP_SUPPORTEDCAPS;
((TW_UINT16*)array->ItemList)[0]=CAP_XFERCOUNT;And i find out the carsh of TWAIN2 sample app is because it call “DG_CONTROL//DAT_CAPABILITY//MSG_GETLABEL//CAP_XFERCOUNT” after “DG_CONTROL//DAT_CAPABILITY//MSG_GET//CAP_SUPPORTEDCAPS” but i didn’t supply this command.
I had such problem before.
And I found two bugs – one in Sample App and one in the DriverIn the Sample App it crashes because the Driver returns TWRC_SUCCESS, but the string was empty.
In the Driver – it must return TWRC_FAILURE/TWCC_CAPBADOPERATION , but not TWRC_SUCCESS if it is not supporting this operation.
- AuthorPosts