/* $Revision: 28 $ $Date: 17/01/06 0:57 $ Copyright © 2002-2006, FSL Technologies Limited. Contact "http://fost3.fsltech.com". */ #include "stdafx.h" #include #include using namespace std; using namespace FSLib; namespace { Revision c_revision( L"$Archive: /FOST.3/F3Util/comType.cpp $", __DATE__, L"$Revision: 28 $", L"$Date: 17/01/06 0:57 $" ); const wchar_t VariantCastMsg[]=L"Variant Cast"; } /* FSLib::Exceptions::VariantCast */ inline FSLib::Exceptions::VariantCast::VariantCast( const FSLib::wstring &s ) : Exception( s ) { } inline const wchar_t * const FSLib::Exceptions::VariantCast::message() const { return VariantCastMsg; } /* The casts */ bool FSLib::VARIANT_is_null( const VARIANT &var ) { try { switch ( var.vt ) { case VT_NULL: case VT_EMPTY: case VT_ERROR: return true; case VT_I8: return false; case VT_DISPATCH: return false; default: return VARIANT_to_wstring( var ).size() == 0; } } catch ( FSLib::Exceptions::Exception &e ) { e.info() << L"Within VARIANT_is_null()" << std::endl << L"VARIANT.vt = " << var.vt << std::endl; throw; } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_is_null()" ); } } FSLib::wstring FSLib::BSTR_to_wstring( const BSTR &bstr ) { try { return FSLib::wstring( static_cast< const wchar_t * >( bstr ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within BSTR_to_wstring()" ); } } void FSLib::wstring_to_BSTR( const FSLib::wstring &str, BSTR &v ) { try { v = ATL::CComBSTR( str.c_str() ).Detach(); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within wstring_to_BSTR()" ); } } long FSLib::VARIANT_to_long( const VARIANT &var ) { try { return static_cast< long >( static_cast< _variant_t >( var ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_long()" ); } } unsigned __int16 FSLib::VARIANT_to_U16( const VARIANT &var ) { try { return static_cast< unsigned __int16 >( static_cast< _variant_t >( var ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_U16()" ); } } bool FSLib::VARIANT_to_bool( const VARIANT &var ) { try { return static_cast< bool >( static_cast< _variant_t >( var ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_bool()" ); } } #pragma warning( push ) #pragma warning( disable : 4702 ) float FSLib::VARIANT_to_float( const VARIANT &var ) { try { return float( static_cast< _variant_t >( var ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_float()" ); } } double FSLib::VARIANT_to_double( const VARIANT &var ) { try { return static_cast< double >( static_cast< _variant_t >( var ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_double()" ); } } #pragma warning( pop ) FSLib::string FSLib::VARIANT_to_string( const VARIANT &var ) { try { return FSLib::string( static_cast< const char * >( static_cast< const _bstr_t >( var ) ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_string()" ); } } FSLib::wstring FSLib::VARIANT_to_wstring( const VARIANT &var ) { try { return FSLib::wstring( static_cast< const wchar_t * >( static_cast< const _bstr_t >( var ) ) ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_wstring()" ); } } Nullable< FSLib::wstring > FSLib::VARIANT_to_Nullable_wstring( const VARIANT &var ) { try { if ( VARIANT_is_null( var ) ) { return Nullable< FSLib::wstring >(); } else { wstring r = VARIANT_to_wstring( var ); if ( r.size() ) return r; else return Null; } } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within VARIANT_to_Nullable_wstring()" ); } } Nullable< FSLib::wstring > FSLib::BSTR_to_Nullable_wstring( const BSTR &bs ) { try { if ( bs == NULL ) return Null; FSLib::wstring ret = BSTR_to_wstring( bs ); if ( ret.size() ) { return ret; } else { return Null; } } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within BSTR_to_Nullable_wstring()" ); } } _variant_t FSLib::wstring_to_VARIANT( const FSLib::wstring &s ) { try { return _variant_t( s.c_str() ); } catch ( _com_error &c ) { throw Exceptions::ComError( c, L"Within wstring_to_VARIANT()" ); } } /* Operators */ bool operator ==( const _variant_t &l, const FSLib::t_null ) { return VARIANT_is_null( l ); } bool operator ==( const FSLib::t_null, const _variant_t &r ) { return VARIANT_is_null( r ); } bool operator !=( const _variant_t &l, const FSLib::t_null ) { return !VARIANT_is_null( l ); } bool operator !=( const FSLib::t_null, const _variant_t &r ) { return !VARIANT_is_null( r ); } /* $History: comType.cpp $ * * ***************** Version 28 ***************** * User: Kirit Date: 17/01/06 Time: 0:57 * Updated in $/FOST.3/F3Util * Additions to string library and variant casts to handle 8 bit strings. * * ***************** Version 27 ***************** * User: Kirit Date: 18/08/05 Time: 13:08 * Updated in $/FOST.3/F3Util * Added unsigned __int16 to variant_cast<> * * ***************** Version 26 ***************** * User: Kirit Date: 5/03/05 Time: 14:10 * Updated in $/FOST.3/F3Util * Added check for NULL BSTR. * * ***************** Version 25 ***************** * User: Kirit Date: 28/01/05 Time: 18:25 * Updated in $/FOST.3/F3Util * Re-wrote VARIANT_is_null to better handle different VARIANT types. * * ***************** Version 24 ***************** * User: Kirit Date: 10/07/04 Time: 11:35 * Updated in $/FOST.3/F3Util * Added new comparison operators for variants. * * ***************** Version 23 ***************** * User: Kirit Date: 6/07/04 Time: 16:47 * Updated in $/FOST.3/F3Util * * Basic Input from multipart encoding of POST data now works. * * Some changes to string handling to support POST data properly. * * ***************** Version 22 ***************** * User: Kirit Date: 5/07/04 Time: 11:39 * Updated in $/FOST.3/F3Util * Changes to Input handling to start to allow reading of user input from * web forms. * * ***************** Version 21 ***************** * User: Kirit Date: 6/12/03 Time: 17:18 * Updated in $/FOST.3/F3Util * Debugged InputCookie and user scheme selection (from a cookie) * * ***************** Version 20 ***************** * User: Kirit Date: 1/12/03 Time: 13:25 * Updated in $/FOST.3/F3Util * Started to put in new Input handling classes. * * ***************** Version 19 ***************** * User: Kirit Date: 15/11/03 Time: 13:21 * Updated in $/FOST.3/F3Util * BSTR can now be cast to a Nullable< wstring > * * ***************** Version 18 ***************** * User: Kirit Date: 6/11/03 Time: 11:52 * Updated in $/FOST.3/F3Util * Fixed bug in determining if a COM object was NULL through a VARIANT. * * ***************** Version 17 ***************** * User: Kirit Date: 27/10/03 Time: 13:16 * Updated in $/FOST.3/F3Util * New property output method works with ability to override default * behaviour on several basis. * * ***************** Version 16 ***************** * User: Kirit Date: 10/10/03 Time: 10:52 * Updated in $/FOST.3/F3Util * F3Base DLL now builds and registers properly. * * ***************** Version 15 ***************** * User: Kirit Date: 9/10/03 Time: 15:44 * Updated in $/FOST.3/F3Util * Headers re-arranged to give a proper SDK feel and to make determination * of required headers simpler. * * ***************** Version 13 ***************** * User: Kirit Date: 3/10/03 Time: 21:30 * Updated in $/FOST/Cpp/FSCOM * Changes to support older compiler. * * ***************** Version 12 ***************** * User: Kirit Date: 3/10/03 Time: 21:10 * Updated in $/FOST.3/F3Util * COM library added to F3Util.DLL * * ***************** Version 11 ***************** * User: Kirit Date: 3/10/03 Time: 16:09 * Updated in $/FOST/Cpp/FSCOM * Added stdafx.h and stdafx.cpp pre-compiled header support. * * ***************** Version 10 ***************** * User: Kirit Date: 5/05/03 Time: 12:55 * Updated in $/FOST/Cpp/FSCOM * Added missing variant_cast support. * * ***************** Version 9 ***************** * User: Kirit Date: 2/07/02 Time: 12:32 * Updated in $/FOST/Cpp/FSCOM * Integrated new attribute and table handling into full source code. * There are still many performance optimisations that should be done, but * the basic mechanism works. * * ***************** Version 8 ***************** * User: Kirit Date: 21/05/02 Time: 13:24 * Updated in $/FOST/Cpp/FSCOM * Changes to support new demonstration and to allow for the addition of * new instances through the web interface. * * ***************** Version 7 ***************** * User: Kirit Date: 7/05/02 Time: 12:01 * Updated in $/FOST/Cpp/FSCOM * Wrapped std::basic_string<> in order to change the copy semantics to * stop the problems with using C++ in the COM layer for IIS. * * ***************** Version 6 ***************** * User: Kirit Date: 19/03/02 Time: 20:54 * Updated in $/FOST/Cpp/FSCOM * Corrected history from last check-in. * Updated TestAX.IDL to remove registry entries from removed classes. * * ***************** Version 5 ***************** * User: Kirit Date: 19/03/02 Time: 19:48 * Updated in $/FOST/Cpp/FSCOM * Debug compiles now all end in '_d'. * The C++ implementation names (Type.cppName) have been changed to also * include the DLL that the implementation is in as per the documentation. * In all source files the following have been done: * * Ensured that every header file has a revision object. * * Ensured that every translation unit has a revision object. * * Ensured that every source file (which understands comments) * has a history section. * * Changed all copyright notices to be for Obsideon Ltd. * * Changed copyright notices to use the longest possible timeframe. * * ***************** Version 4 ***************** * User: Kirit Date: 11/03/02 Time: 23:09 * Updated in $/FOST/Cpp/FSCOM * Changed TestAX.LibFAg.FromSQL to take a VARIANT so that ordinals could * be used. * Added variant_cast to FSCOM.DLL. * Changed field_cast to use variant_cast and to allow for the use of an * ordinal number. * Changed FSLib::Recordset::field so that it can take an ordinal number, * but also so that it caches the column values. * * ***************** Version 3 ***************** * User: Kirit Date: 11/03/02 Time: 16:13 * Updated in $/FOST/Cpp/FSCOM * Addition of TestAX.HTML01.Block and changes in the class HTML search * order. * * ***************** Version 2 ***************** * User: Kirit Date: 25/02/02 Time: 23:22 * Updated in $/FOST/Cpp/FSCOM * New HTML generation component. * Required addition to FSLib::Setting interface to read a value with a * default provided at runtime. * * ***************** Version 1 ***************** * User: Kirit Date: 20/02/02 Time: 16:04 * Created in $/FOST/Cpp/FSCOM */