From: Jaakko Salli Date: Sat, 3 Oct 2009 10:43:21 +0000 (+0000) Subject: Added wxDECLARE_ANY_TYPE(CLS, DECL) and documented for what kind of situation it... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c5fe6a5bee092251f08fa204c8857c36af865157 Added wxDECLARE_ANY_TYPE(CLS, DECL) and documented for what kind of situation it is intended: wxAny used across DLL and EXE boundaries. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62230 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/any.h b/include/wx/any.h index 0784b66480..52d8480b66 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -479,6 +479,53 @@ WX_ANY_DEFINE_SUB_TYPE(float, Double) WX_ANY_DEFINE_SUB_TYPE(double, Double) +// +// Defines a dummy wxAnyValueTypeImpl<> with given export +// declaration. This is needed if a class is used with +// wxAny in both user shared library and application. +// +#define wxDECLARE_ANY_TYPE(CLS, DECL) \ +template<> \ +class DECL wxAnyValueTypeImpl : \ + public wxAnyValueTypeImplBase \ +{ \ + WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl) \ +public: \ + wxAnyValueTypeImpl() : \ + wxAnyValueTypeImplBase() { } \ + virtual ~wxAnyValueTypeImpl() { } \ + \ + virtual bool ConvertValue(const wxAnyValueBuffer& src, \ + wxAnyValueType* dstType, \ + wxAnyValueBuffer& dst) const \ + { \ + wxUnusedVar(src); \ + wxUnusedVar(dstType); \ + wxUnusedVar(dst); \ + return false; \ + } \ +}; + + +// Make sure some of wx's own types get the right wxAnyValueType export +// (this is needed only for types that are referred to from wxBase. +// currently we may not use any of these types from there, but let's +// use the macro on at least one to make sure it compiles since we can't +// really test it properly in unittests since a separate DLL would +// be needed). +#if wxUSE_DATETIME + #include "wx/datetime.h" + wxDECLARE_ANY_TYPE(wxDateTime, WXDLLIMPEXP_BASE) +#endif + +//#include "wx/object.h" +//wxDECLARE_ANY_TYPE(wxObject*, WXDLLIMPEXP_BASE) + +//#include "wx/arrstr.h" +//wxDECLARE_ANY_TYPE(wxArrayString, WXDLLIMPEXP_BASE) + + + #ifdef __VISUALC6__ // Re-enable useless VC6 warnings #pragma warning (pop) diff --git a/interface/wx/any.h b/interface/wx/any.h index c1893fbfe6..d8e69cbc58 100644 --- a/interface/wx/any.h +++ b/interface/wx/any.h @@ -63,6 +63,25 @@ Note that pointers to any and all classes are already automatically declared as movable data. + @warning Caveat with shared libraries (DLLs): If you have a scenario where + you use wxAny across application's shared library and application + itself (or, with another of your shared libraries), then you must + use wxDECLARE_ANY_TYPE() macro in your shared library code to + correctly make sure that the wxAnyValueType implementation is + generated correctly. Failure to do this will result in breakage + of the wxAny type recognition with type in question. Below is an + example how to use the macro. + @code + // In your shared library/DLL-only + wxDECLARE_ANY_TYPE(MyClass, WXEXPORT) + + // In your shared library/DLL source code + WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) + + // In code using said shared library/DLL + wxDECLARE_ANY_TYPE(MyClass, WXIMPORT) + @endcode + @library{wxbase} @category{data} diff --git a/src/common/any.cpp b/src/common/any.cpp index 01658ab8b7..1b12110c3f 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -339,6 +339,10 @@ WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplString) WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImplDouble) +WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) +//WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) + //------------------------------------------------------------------------- // wxAnyNullValueType implementation //-------------------------------------------------------------------------