+// This one is a macro so that it can be tested with #ifdef, it will be
+// undefined if it cannot be implemented for a given compiler.
+// Vc++, bcc, dmc, ow, mingw akk have _get_osfhandle() and Cygwin has
+// get_osfhandle. Others are currently unknown, e.g. Salford, Intel, Visual
+// Age.
+#if defined(__WXWINCE__)
+ #define wxGetOSFHandle(fd) ((HANDLE)fd)
+ #define wxOpenOSFHandle(h, flags) ((int)wxPtrToUInt(h))
+#elif defined(__CYGWIN__)
+ #define wxGetOSFHandle(fd) ((HANDLE)get_osfhandle(fd))
+#elif defined(__VISUALC__) \
+ || defined(__BORLANDC__) \
+ || defined(__DMC__) \
+ || defined(__WATCOMC__) \
+ || defined(__MINGW32__)
+ #define wxGetOSFHandle(fd) ((HANDLE)_get_osfhandle(fd))
+ #define wxOpenOSFHandle(h, flags) (_open_osfhandle(wxPtrToUInt(h), flags))
+ #define wx_fdopen _fdopen
+#endif
+
+// close the handle in the class dtor
+class AutoHANDLE
+{
+public:
+ wxEXPLICIT AutoHANDLE(HANDLE handle) : m_handle(handle) { }
+
+ bool IsOk() const { return m_handle != INVALID_HANDLE_VALUE; }
+ operator HANDLE() const { return m_handle; }
+
+ ~AutoHANDLE() { if ( IsOk() ) ::CloseHandle(m_handle); }
+
+protected:
+ HANDLE m_handle;
+};
+
+// a template to make initializing Windows styructs less painful: it zeroes all
+// the struct fields and also sets cbSize member to the correct value (and so
+// can be only used with structures which have this member...)
+template <class T>
+struct WinStruct : public T
+{
+ WinStruct()
+ {
+ ::ZeroMemory(this, sizeof(T));
+
+ // explicit qualification is required here for this to be valid C++
+ this->cbSize = sizeof(T);
+ }
+};
+
+
+// Macros for converting wxString to the type expected by API functions.
+//
+// Normally it is enough to just use wxString::t_str() which is implicitly
+// convertible to LPCTSTR, but in some cases an explicit conversion is required.
+//
+// In such cases wxMSW_CONV_LPCTSTR() should be used. But if an API function
+// takes a non-const pointer, wxMSW_CONV_LPTSTR() which casts away the
+// constness (but doesn't make it possible to really modify the returned
+// pointer, of course) should be used. And if a string is passed as LPARAM, use
+// wxMSW_CONV_LPARAM() which does the required ugly reinterpret_cast<> too.
+#define wxMSW_CONV_LPCTSTR(s) static_cast<const wxChar *>((s).t_str())
+#define wxMSW_CONV_LPTSTR(s) const_cast<wxChar *>(wxMSW_CONV_LPCTSTR(s))
+#define wxMSW_CONV_LPARAM(s) reinterpret_cast<LPARAM>(wxMSW_CONV_LPCTSTR(s))
+
+