Add wxLoadUserResource() overload not copying the resource data.

The existing wxLoadUserResource() copies the resource data which is often
unnecessary. Add another overload which just returns the pointer directly to
the resource data.

Also move the function into base from core as it can be useful for the console
applications as well.

Finally, define wxUserResourceStr used by this function only in the same file
where the function itself is defined instead of datacmn.cpp.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64150 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-04-26 16:53:21 +00:00
parent ea85e5e0c6
commit c5ba485124
4 changed files with 87 additions and 48 deletions

View File

@@ -676,10 +676,31 @@ public:
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
// ----------------------------------------------------------------------------