Пример #1
0
PWSTR CTextObject::CreateDataFile(const void* pData, int nDataSize)
{
	TCHAR szTempPath[MAX_PATH];
	GetTempPath(countof(szTempPath), szTempPath);
	TCHAR szTempFileName[MAX_PATH];
	GetTempFileName(szTempPath, _T("OBJ"), 0, szTempFileName);
	if (! StoreDataToFile(szTempFileName, pData, nDataSize))
		return NULL;
	PWSTR pszFileName = (PWSTR)CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
	if (pszFileName == NULL)
	{
		DeleteFile(szTempFileName);
		return NULL;
	}
#ifdef _UNICODE
	wcscpy_s(pszFileName, MAX_PATH, szTempFileName);
#else
	if (! MultiByteToWideChar(CP_ACP, 0, szTempFileName, -1, pszFileName, MAX_PATH))
	{
		DeleteFile(szTempFileName);
		CoTaskMemFree(pszFileName);
		return NULL;
	}
#endif
	return pszFileName;
}
Пример #2
0
HRESULT CTextObject::InitializeDataHere(STGMEDIUM* pMedium, const void* pData, int nDataSize)
{
	switch (pMedium->tymed)
	{
	case TYMED_HGLOBAL:
		{
			HGLOBAL hGlobal = pMedium->hGlobal;
			if (hGlobal == NULL)
				return DV_E_FORMATETC;
			hGlobal = GlobalReAlloc(hGlobal, nDataSize, 0);
			if (hGlobal == NULL)
				return E_OUTOFMEMORY;
			ATLASSERT(pMedium->hGlobal == hGlobal);
			CopyMemory(GlobalLock(hGlobal), pData, nDataSize);
			GlobalUnlock(hGlobal);
		}
		break;
	case TYMED_FILE:
		{
			PWSTR pszFileName = pMedium->lpszFileName;
			if (pszFileName == NULL)
				return DV_E_FORMATETC;
			if (! StoreDataToFile(CW2TEX<MAX_PATH>(pszFileName), pData, nDataSize))
				return STG_E_MEDIUMFULL;
		}
		break;
	case TYMED_ISTREAM:
		{
			IStream* pStream = pMedium->pstm;
			if (pStream == NULL)
				return DV_E_FORMATETC;
			HRESULT hRes = pStream->Write(pData, nDataSize, NULL);
			if (FAILED(hRes))
				return hRes;
		}
		break;
	}
	pMedium->pUnkForRelease = NULL;
	return S_OK;
}
Пример #3
0
int convert(char *inFile, char *outFile)    
{
    sint32 retVal = 0;

    uint32 versionMajor = 0;
    uint32 versionMinor = 0;

    unsigned char *pInputBuffer = NULL;
    unsigned char *pOutputBuffer = NULL;
    uint32 lenInput = 0;
    uint32 lenOutput = 0;

    retVal = BCGetVersion( &versionMajor, &versionMinor );
    // Get library version and print it
    printf( "\nBiodata Conversion Library version %d.%d convert template sample\n",
        versionMajor, versionMinor );

    // Check command line parameters count
    

        // Read template from file

        retVal = LoadDataFromFile( inFile, &pInputBuffer, &lenInput );
        if ( retVal < 0 )
        {
            printf( "Error reading file '%s' (code %d)\n", inFile, retVal );
        }
        else
        {
            // Get output data langth
    
            retVal = BCConvertTemplate( BCTE_NONE, BCT_ISO_FMR, 
                pInputBuffer, lenInput,
                BCTE_PT_BIR, BCT_UPEK_LEGACY,
                NULL, &lenOutput,
                NULL );

            if ( retVal != BCERR_OK )
            {
                // Cannot get output lenght, report error
                
                printf( "Error getting output length (code %d)\n",
                    retVal );
            }
            else
            {
                // Allocate memory 

                pOutputBuffer = (unsigned char *) malloc( lenOutput );

                // Call conversion
    
                retVal = BCConvertTemplate( BCTE_NONE, BCT_ISO_FMR, 
                    pInputBuffer, lenInput,
                    BCTE_PT_BIR, BCT_UPEK_LEGACY,
                    pOutputBuffer, &lenOutput,
                    NULL );
            
                if ( retVal == BCERR_OK )
                {
                    // Success, store data to file
                
                    StoreDataToFile( outFile, pOutputBuffer, lenOutput );
                    printf( "File '%s' converted to '%s'\n",
                        inFile, outFile );
                }
                else
                {
                    // Conversion failed, report error
                
                    printf( "Error converting file '%s' (code %d)\n",
                        inFile, retVal );
                }
            }
        }

    // Cleanup
    
    if ( pInputBuffer != NULL )
    {
        free( pInputBuffer );
    }

    if ( pOutputBuffer != NULL )
    {
        free( pOutputBuffer );
    }

    return retVal;
}