Пример #1
0
bool StillImage::RegisterApplication(HINSTANCE hInstace)
{
	CComPtr<IStillImage> pSti = GetStillImage(hInstace);

	if (pSti == 0)
		return false;

    return pSti->RegisterLaunchApplication(CT2W(GetAppName()), CT2W(GetExePath())) == S_OK;
}
Пример #2
0
bool StillImage::UnregisterApplication(HINSTANCE hInstace)
{
    CComPtr<IStillImage> pSti = GetStillImage(hInstace);

	if (pSti == 0)
		return false;

	USES_CONVERSION;

    return pSti->UnregisterLaunchApplication(CT2W(GetAppName())) == S_OK;
}
Пример #3
0
bool StillImage::IsLaunchedByEventMonitor(HINSTANCE hInstace, IEvents *pFrame)
{
    USES_CONVERSION;
    HRESULT       hr;
    bool          bLaunchedByEventManager = false;
    WCHAR         szDeviceName[STI_MAX_INTERNAL_NAME_LENGTH];
    DWORD         dwEventCode;
    WCHAR         szEventName[64];
    GUID          guidEventName;
    TCHAR         szTwainName[sizeof(TW_STR32)]; // sizeof(TW_IDENTITY::ProductName)
    DWORD         dwTwainNameSize = sizeof(szTwainName);
    bool          bScan = false;
    bool          bPrint = false;


   CComPtr<IStillImage> pSti = GetStillImage(hInstace);

	if (pSti == 0)
		return false;

    if (pSti->RegisterLaunchApplication(CT2W(GetAppName()), CT2W(GetExePath())) != S_OK)
		return false;

    hr = pSti->GetSTILaunchInformation(szDeviceName, &dwEventCode, szEventName);

    if (hr == S_OK) 
	{
        // if we are launched by the event manager, determine the event type
        bLaunchedByEventManager = TRUE;

        if (CLSIDFromString(szEventName, &guidEventName) != S_OK)
		{
			return false;
		}

		if (IW::InlineIsEqualGUID(guidEventName, xGUID_DeviceArrivedLaunch)) 
		{
            bScan = true;
        } 
		else if (IW::InlineIsEqualGUID(guidEventName, xGUID_ScanImage)) 
		{
            bScan = true;
        } 
		else if (IW::InlineIsEqualGUID(guidEventName, xGUID_ScanPrintImage)) 
		{
            bScan = true;
            bPrint = true;
        } 
		else 
		{
            return false;
        }

        // if we are supposed to get the image from the device,
        // get the TWAIN source name and pop up the scan dialog
        if (bScan) 
		{

            if (!pSti->GetDeviceValue(szDeviceName, STI_DEVICE_VALUE_TWAIN_NAME, 0, (PBYTE) szTwainName, &dwTwainNameSize) != S_OK)
			{
				return false;
			}

            pFrame->TwainAcquire(szTwainName);
        }

        // if we are supposed to print the image afterwards, 
        // pop up the print dialog
        if (bPrint) 
		{
			// Print?
        }
    }

    return bLaunchedByEventManager;
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// GetPropertyData()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	void FormatList::GetPropertyData(const CMIOObjectPropertyAddress& address, UInt32 qualifierDataSize, const void* qualifierData, UInt32 dataSize, UInt32& dataUsed, void* data) const
	{
		Float64* rates;
		AudioValueRange* rateRanges;
		UInt32 theNumberRates;
		UInt32 theNumberRateRanges;
		UInt32 theIndex;
		CMFormatDescriptionRef format = NULL;
		
		switch (address.mSelector)
		{
			case kCMIOStreamPropertyFormatDescription:
				ThrowIf(dataSize != sizeof(CMFormatDescriptionRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyFormatDescription");
				if (NULL != GetCurrentFormat()) CFRetain(GetCurrentFormat());
				*static_cast<CMFormatDescriptionRef*>(data) = GetCurrentFormat();
				dataUsed = sizeof(CMFormatDescriptionRef);
				break;
				
			case kCMIOStreamPropertyFormatDescriptions:
				ThrowIf(dataSize != sizeof(CFArrayRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyFormatDescriptions");
				*static_cast<CFArrayRef*>(data) = CFArrayCreateCopy(NULL, mDescriptions.GetCFArray());
				dataUsed = sizeof(CFArrayRef);
				break;

			case kCMIOStreamPropertyStillImage:
				ThrowIf(dataSize != sizeof(CMSampleBufferRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyStillImage");
				ThrowIf(qualifierDataSize != sizeof(CMFormatDescriptionRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong qualifier data size for kCMIOStreamPropertyStillImage");
				*static_cast<CMSampleBufferRef*>(data) = GetStillImage(*static_cast<CMFormatDescriptionRef*>(const_cast<void*>(qualifierData)));
				dataUsed = sizeof(CMFormatDescriptionRef);
				break;
				
			case kCMIOStreamPropertyStillImageFormatDescriptions:
				ThrowIf(dataSize != sizeof(CFArrayRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyStillImageFormatDescriptions");
				*static_cast<CFArrayRef*>(data) = CFArrayCreateCopy(NULL, mStillImageDescriptions.GetCFArray());
				dataUsed = sizeof(CFArrayRef);
				break;

			case kCMIOStreamPropertyFrameRate:
				ThrowIf(dataSize != sizeof(Float64), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyFrameRate");
				*(static_cast<Float64*>(data)) = GetCurrentFrameRate();
				dataUsed = sizeof(Float64);
				break;
				
			case kCMIOStreamPropertyFrameRates:
				ThrowIf(qualifierDataSize != 0 and qualifierDataSize != sizeof(CMFormatDescriptionRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong qualifier data size for kCMIOStreamPropertyFrameRates");
				format = (0 == qualifierDataSize) ? mCurrentFormat.Get() : *static_cast<CMFormatDescriptionRef*>(const_cast<void*>(qualifierData));
				theNumberRates = std::min((UInt32)(dataSize / sizeof(Float64)), GetNumberFrameRates(format));
				rates = static_cast<Float64*>(data);
				for(theIndex = 0; theIndex < theNumberRates; ++theIndex)
				{
					rates[theIndex] = GetFrameRateByIndex(format, theIndex);
				}
				dataUsed = theNumberRates * sizeof(Float64);
				break;
			
			case kCMIOStreamPropertyMinimumFrameRate:
				ThrowIf(dataSize != sizeof(Float64), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyMinimumFrameRate");
				*(static_cast<Float64*>(data)) = GetMinimumFrameRate();
				dataUsed = sizeof(Float64);
				break;
				
			case kCMIOStreamPropertyFrameRateRanges:
				ThrowIf(qualifierDataSize != 0 and qualifierDataSize != sizeof(CMFormatDescriptionRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong qualifier data size for kCMIOStreamPropertyFrameRateRanges");
				format = (0 == qualifierDataSize) ? mCurrentFormat.Get() : *static_cast<CMFormatDescriptionRef*>(const_cast<void*>(qualifierData));
				theNumberRateRanges = std::min((UInt32)(dataSize / sizeof(AudioValueRange)), GetNumberFrameRateRanges(format));
				rateRanges = static_cast<AudioValueRange*>(data);
				for(theIndex = 0; theIndex < theNumberRateRanges; ++theIndex)
				{
					rateRanges[theIndex] = GetFrameRateRangeByIndex(format, theIndex);
				}
				dataUsed = theNumberRateRanges * sizeof(AudioValueRange);
				break;
				
			case kCMIOStreamPropertyPreferredFormatDescription:
				ThrowIf(dataSize != sizeof(CMFormatDescriptionRef), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyPreferredFormatDescription");
				if (NULL != GetPreferredFormat()) CFRetain(GetPreferredFormat());
				*static_cast<CMFormatDescriptionRef*>(data) = GetPreferredFormat();
				dataUsed = sizeof(CMFormatDescriptionRef);
				break;

			case kCMIOStreamPropertyPreferredFrameRate:
				ThrowIf(dataSize != sizeof(Float64), CAException(kCMIOHardwareBadPropertySizeError), "CMIO::DP::FormatList::GetPropertyData: wrong data size for kCMIOStreamPropertyPreferredFrameRate");
				*(static_cast<Float64*>(data)) = GetPreferredFrameRate();
				dataUsed = sizeof(Float64);
				break;
				
		};
	}