void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y );
// MSW only: get user-defined resource from the .res file.
-// Returns NULL or newly-allocated memory, so use delete[] to clean up.
#ifdef __WXMSW__
- extern WXDLLIMPEXP_CORE const wxChar* wxUserResourceStr;
- WXDLLIMPEXP_CORE char* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr, int* pLen = NULL);
+ // default resource type for wxLoadUserResource()
+ extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxUserResourceStr;
+
+ // Return the pointer to the resource data. This pointer is read-only, use
+ // the overload below if you need to modify the data.
+ //
+ // Returns true on success, false on failure. Doesn't log an error message
+ // if the resource is not found (because this could be expected) but does
+ // log one if any other error occurs.
+ WXDLLIMPEXP_BASE bool
+ wxLoadUserResource(const void **outData,
+ size_t *outLen,
+ const wxString& resourceName,
+ const wxString& resourceType = wxUserResourceStr);
+
+ // This function allocates a new buffer and makes a copy of the resource
+ // data, remember to delete[] the buffer. And avoid using it entirely if
+ // the overload above can be used.
+ //
+ // Returns NULL on failure.
+ WXDLLIMPEXP_BASE char*
+ wxLoadUserResource(const wxString& resourceName,
+ const wxString& resourceType = wxUserResourceStr,
+ int* pLen = NULL);
#endif // MSW
// ----------------------------------------------------------------------------
extern WXDLLEXPORT_DATA(const char) wxDirDialogDefaultFolderStr[] = "/";
extern WXDLLEXPORT_DATA(const char) wxFileDialogNameStr[] = "filedlg";
-#if defined(__WXMSW__) || defined(__OS2__)
-WXDLLEXPORT_DATA(const wxChar *) wxUserResourceStr = wxT("TEXT");
-#endif
static const wxChar eUSERNAME[] = wxT("UserName");
#endif
+WXDLLIMPEXP_DATA_BASE(const wxChar *) wxUserResourceStr = wxT("TEXT");
+
// ============================================================================
// implementation
// ============================================================================
#endif
}
+// ----------------------------------------------------------------------------
+// working with MSW resources
+// ----------------------------------------------------------------------------
+
+bool
+wxLoadUserResource(const void **outData,
+ size_t *outLen,
+ const wxString& resourceName,
+ const wxString& resourceType)
+{
+ wxCHECK_MSG( outData && outLen, false, "output pointers can't be NULL" );
+
+ HRSRC hResource = ::FindResource(wxGetInstance(),
+ resourceName.wx_str(),
+ resourceType.wx_str());
+ if ( !hResource )
+ return false;
+
+ HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
+ if ( !hData )
+ {
+ wxLogSysError(_("Failed to load resource \"%s\"."), resourceName);
+ return false;
+ }
+
+ *outData = ::LockResource(hData);
+ if ( !*outData )
+ {
+ wxLogSysError(_("Failed to lock resource \"%s\"."), resourceName);
+ return false;
+ }
+
+ *outLen = ::SizeofResource(wxGetInstance(), hResource);
+
+ // Notice that we do not need to call neither UnlockResource() (which is
+ // obsolete in Win32) nor GlobalFree() (resources are freed on process
+ // termination only)
+
+ return true;
+}
+
+char *
+wxLoadUserResource(const wxString& resourceName,
+ const wxString& resourceType,
+ int* pLen)
+{
+ const void *data;
+ size_t len;
+ if ( !wxLoadUserResource(&data, &len, resourceName, resourceType) )
+ return NULL;
+
+ char *s = new char[len + 1];
+ memcpy(s, data, len);
+ s[len] = '\0'; // NUL-terminate in case the resource itself wasn't
+
+ if (pLen)
+ *pLen = len;
+
+ return s;
+}
+
// ----------------------------------------------------------------------------
// OS version
// ----------------------------------------------------------------------------
return true;
}
-// MSW only: get user-defined resource from the .res file.
-// Returns NULL or newly-allocated memory, so use delete[] to clean up.
-
-#ifndef __WXMICROWIN__
-char *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType, int* pLen /* = NULL */)
-{
- HRSRC hResource = ::FindResource(wxGetInstance(),
- resourceName.wx_str(),
- resourceType.wx_str());
- if ( hResource == 0 )
- return NULL;
-
- HGLOBAL hData = ::LoadResource(wxGetInstance(), hResource);
- if ( hData == 0 )
- return NULL;
-
- void *theText = ::LockResource(hData);
- if ( !theText )
- return NULL;
-
- // Not all compilers put a zero at the end of the resource (e.g. BC++ doesn't).
- // so we need to find the length of the resource.
- int len = ::SizeofResource(wxGetInstance(), hResource);
- char *s = new char[len + 1];
- memcpy(s, theText, len);
- s[len] = '\0'; // NUL-terminate in case the resource itself wasn't
-
- // Obsolete in WIN32
-#ifndef __WIN32__
- UnlockResource(hData);
-#endif
-
- // No need??
- // GlobalFree(hData);
-
- if (pLen)
- *pLen = len;
-
- return s;
-}
-#endif // __WXMICROWIN__
-
// ----------------------------------------------------------------------------
// get display info
// ----------------------------------------------------------------------------