⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twd_com.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	                *((pTW_INT16)pVoid+j) = *((pTW_INT16)pList+j);
                    break;

    		    case TWTY_INT32:
	                *((pTW_INT32)pVoid+j) = *((pTW_INT32)pList+j);
                    break;

    		    case TWTY_UINT8:
	                *((pTW_UINT8)pVoid+j) = *((pTW_UINT8)pList+j);
                    break;

	            case TWTY_UINT16:
	                *((pTW_UINT16)pVoid+j) = *((pTW_UINT16)pList+j);
                    break;

	            case TWTY_UINT32:
	                *((pTW_UINT32)pVoid+j) = *((pTW_UINT32)pList+j);
                    break;

	            case TWTY_BOOL:
	                *((pTW_BOOL)pVoid+j) = *((pTW_BOOL)pList+j);
                    break;

                case TWTY_FIX32:
		            *((pTW_FIX32)pVoid+j) = *((pTW_FIX32)pList+j);
		            break;

		        case TWTY_FRAME:
		            *((pTW_FRAME)pVoid+j) = *((pTW_FRAME)pList+j);
    			    break;

	    	    case TWTY_STR32:
		            *((pTW_STR32)pVoid+j) = *((pTW_STR32)pList+j);
    			    break;

	    	    case TWTY_STR64:
		            *((pTW_STR64)pVoid+j) = *((pTW_STR64)pList+j);
    			    break;

	    	    case TWTY_STR128:
		            *((pTW_STR128)pVoid+j) = *((pTW_STR128)pList+j);
    			    break;

	    	    case TWTY_STR255:
		            *((pTW_STR255)pVoid+j) = *((pTW_STR255)pList+j);
    			    break;

		        default:
	                // bad ItemType
	                break;
            } // end of switch
        } // end of for loop

        GlobalUnlock(pData->hContainer);
    }

    // now you have a dynamically sized array WITHIN a struct
    return;
}  // BuildUpArrayType


///////////////////////////////////////////////////////////////////////////////////////
// BuildUpRangeType --
//
VOID BuildUpRangeType(pTW_CAPABILITY pData, pTW_RANGE pr, TW_UINT16 msg)
{
	pTW_RANGE pRange;

    if (msg != MSG_SET)	// MSG_SET allocates the structure at the app
	{
	    if ((pData->hContainer = (TW_HANDLE)GlobalAlloc(GMEM_MOVEABLE,
	    	sizeof(TW_RANGE))) == NULL)
				return;
	}
	 pData->ConType = TWON_RANGE;
	 if ((pRange = (pTW_RANGE)GlobalLock(pData->hContainer))!=NULL)
	 {
	 	pRange->ItemType = pr->ItemType;
		pRange->MinValue = pr->MinValue; 
		pRange->MaxValue = pr->MaxValue;
		pRange->StepSize = pr->StepSize;
		pRange->DefaultValue = pr->DefaultValue;
		pRange->CurrentValue = pr->CurrentValue;
	 	
	 	GlobalUnlock(pData->hContainer);	
	 }
}

/***********************************************************************
 * FUNCTION: BuildOneValue 设置单属性值
 *
 * ARGS:    pData   指向属性结构的指针
 *          ItemType 下面各项类型的常量
 *          Item    放入属性栏的数据
 *
 * RETURNS: pData->hContainer 返回指向属性地址的指针
 *
 * NOTES:   This routine responds to a CAP_ call by creating a container of 
 * type OneValue and returning with the hContainer value (excuse me) "pointing"
 * to the container.  The container is filled with the values for ItemType
 * and Item requested by the caller.
 *
 * NOTE: be sure to tell the APP the container type you have built, ConType.
 *
 * Protocol: Used by MSG_GET.. calls were Source allocates the container and the
 * APP uses and then frees the container.
 *
 * For generalization value of ItemType does not affect Item in anyway.
 * Caller should cast Item to TW_UINT32.
 */
TW_UINT16 BuildUpOneValue (pTW_CAPABILITY pData, TW_UINT16 ItemType, void *Item, TW_UINT16 msg)
{
    pTW_ONEVALUE pOneValue;
	
    if (msg != MSG_SET)	// MSG_SET allocates the structure at the app
	{
	    if ((pData->hContainer = (TW_HANDLE)GlobalAlloc(GMEM_MOVEABLE,
	    	sizeof(TW_ONEVALUE))) == NULL)
				return(TWCC_LOWMEMORY);
	}

    // tell APP the ConType returning
    pData->ConType = TWON_ONEVALUE;
    if ((pOneValue = (pTW_ONEVALUE)GlobalLock(pData->hContainer)) != NULL)
    {
        pOneValue->ItemType = ItemType; 
        switch(ItemType)
        {
			case TWTY_FIX32:
				//fix32.Whole = &Item->Whole;
				//fix32.Frac = 32;
				//pOneValue->Item = *((pTW_INT32)&fix32);
				//pOneValue->Item = *((pTW_INT32)&Item);
				pOneValue->Item = (TW_UINT32)Item; 
				break;	
			
			default:
				pOneValue->Item = (TW_UINT32)Item; 
        		break;
        }   
         
        GlobalUnlock(pData->hContainer);
    }
	
    return(TWCC_SUCCESS);
} // BuildUpOneValue


/***********************************************************************
 * FUNCTION: ExtractOneValue 
 *
 * ARGS:    pData   pointer to a capability structure, details about container
 *          pVoid   ptr will be set to point to the item on return
 *
 * RETURNS: pVoid pts to extracted value.
 *
 * NOTES:   This routine will open a container and extract the Item.  The Item 
 * will be returned to the caller in pVoid.  I will type cast the returned 
 * value to that of ItemType.
 *  
 * Protocol: used by MSG_SET calls were Source empties then App frees.  It is 
 * also assumed that the APP allocates and fills the container BEFORE this
 * call.
 */   
VOID ExtractOneValue (pTW_CAPABILITY pData, LPVOID pVoid)
{
    pTW_ONEVALUE pOneValue;

    if ((pOneValue = (pTW_ONEVALUE)GlobalLock(pData->hContainer)) != NULL)
    {
	
        // add a check for valid type
        // CAST to type of var caller wants
        switch (pOneValue->ItemType)
        {
    	    case TWTY_INT8:
	            *(pTW_INT8)pVoid = (TW_INT8)pOneValue->Item;
                break;
            
    	    case TWTY_UINT8:
	            *(pTW_UINT8)pVoid = (TW_UINT8)pOneValue->Item;
                break;

    	    case TWTY_INT16:
	            *(pTW_INT16)pVoid = (TW_INT16)pOneValue->Item;
                break;
            
    	    case TWTY_UINT16:
	            *(pTW_UINT16)pVoid = (TW_UINT16)pOneValue->Item;
                break;

    	    case TWTY_INT32:
	            *(pTW_INT32)pVoid = (TW_INT32)pOneValue->Item;
                break;
  
    	    case TWTY_UINT32:
	            *(pTW_UINT32)pVoid = (TW_UINT32)pOneValue->Item;
                break;

    	    case TWTY_BOOL:
	            *(pTW_BOOL)pVoid = (TW_BOOL)pOneValue->Item;
                break;

/* bugger
    	    case TWTY_FIX32:
	            *(pTW_FIX32)pVoid = (TW_FIX32)pOneValue->Item;
        	    break;

	        case TWTY_FRAME:
	            *(pTW_FRAME)pVoid = (TW_FRAME)pOneValue->Item;
        	    break;

    	    case TWTY_STR32:
	            *(pTW_STR32)pVoid = (TW_STR32)pOneValue->Item;
        	    break;

	        case TWTY_STR64:
    	        *(pTW_STR64)pVoid = (TW_STR64)pOneValue->Item;
	            break;

    	    case TWTY_STR128:
	            *(pTW_STR128)pVoid = (TW_STR128)pOneValue->Item;
        	    break;

    	    case TWTY_STR255:
	            *(pTW_STR255)pVoid = (TW_STR255)pOneValue->Item;
        	    break;

*/
	        default:
	            break;
	    }
 
        GlobalUnlock(pData->hContainer);
    }

    // it is assumed that the App will free the container upon return
    return;
} // ExtractOneValue



/***********************************************************************
 * FUNCTION: AltTWItemSize
 *
 * ARGS:    ItemType    constant which serves as an index to appropiate
 *                      data type
 * RETURNS: Result      size of item in bytes
 *
 * NOTES:   The routine provides a look-up table to get actual size in bytes of 
 * a particular data type.  Using the sizeof call should give the correct
 * results on any machine type.  The value for the ItemType parm are found
 * in the twain.h file and are indicated by TWTY_XXXX.. (TWTY_UINT16...)
 * 
 * This routine is provided to allow the Source to use this code intact.  The
 * Source does not link to the TWA_GLUE.C module and thus does not have access
 * to the TWItemSize array.
 */   
TW_UINT16 AltTWItemSize(TW_INT16 ItemType)
{
    TW_UINT16 result=sizeof(TW_UINT16);

    switch (ItemType)
    {
    	case TWTY_INT8:
	        result = sizeof(TW_INT8);
            break;

    	case TWTY_UINT8:
    	    result = sizeof(TW_UINT8);
            break;

    	case TWTY_INT16:
	        result = sizeof(TW_INT16);
            break;

       	case TWTY_UINT16:
        	result = sizeof(TW_UINT16);
            break;

    	case TWTY_INT32:
	        result = sizeof(TW_INT32);
            break;

    	case TWTY_UINT32:
            result = sizeof(TW_UINT32);
            break;

        default:
            break;
    }

    return(result);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -