Change wxMSW-specific wxLoadUserResource() to accept standard RT_XXX types.

Resource types can be either strings for custom types or integers casted to a
TCHAR* for the standard ones. Using wxString for the resource type prevented
us from using the latter as any attempt to initialize wxString for such a
pseudo-string resulted in an immediate crash.

Change wxLoadUserResource() resource type parameter type to wxChar* to avoid
this and allow passing standard resource types, such as RT_RCDATE, to this
function directly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72472 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-13 17:13:28 +00:00
parent 9a0f0f462f
commit e23fd60fe7
2 changed files with 9 additions and 5 deletions

View File

@@ -818,6 +818,10 @@ WXDLLIMPEXP_CORE bool wxYieldIfNeeded();
// Return the pointer to the resource data. This pointer is read-only, use // Return the pointer to the resource data. This pointer is read-only, use
// the overload below if you need to modify the data. // the overload below if you need to modify the data.
// //
// Notice that the resource type can be either a real string or an integer
// produced by MAKEINTRESOURCE(). In particular, any standard resource type,
// i.e any RT_XXX constant, could be passed here.
//
// Returns true on success, false on failure. Doesn't log an error message // 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 // if the resource is not found (because this could be expected) but does
// log one if any other error occurs. // log one if any other error occurs.
@@ -825,7 +829,7 @@ WXDLLIMPEXP_CORE bool wxYieldIfNeeded();
wxLoadUserResource(const void **outData, wxLoadUserResource(const void **outData,
size_t *outLen, size_t *outLen,
const wxString& resourceName, const wxString& resourceName,
const wxString& resourceType = wxUserResourceStr, const wxChar* resourceType = wxUserResourceStr,
WXHINSTANCE module = 0); WXHINSTANCE module = 0);
// This function allocates a new buffer and makes a copy of the resource // This function allocates a new buffer and makes a copy of the resource
@@ -835,7 +839,7 @@ WXDLLIMPEXP_CORE bool wxYieldIfNeeded();
// Returns NULL on failure. // Returns NULL on failure.
WXDLLIMPEXP_BASE char* WXDLLIMPEXP_BASE char*
wxLoadUserResource(const wxString& resourceName, wxLoadUserResource(const wxString& resourceName,
const wxString& resourceType = wxUserResourceStr, const wxChar* resourceType = wxUserResourceStr,
int* pLen = NULL, int* pLen = NULL,
WXHINSTANCE module = 0); WXHINSTANCE module = 0);
#endif // __WINDOWS__ #endif // __WINDOWS__

View File

@@ -1103,14 +1103,14 @@ bool
wxLoadUserResource(const void **outData, wxLoadUserResource(const void **outData,
size_t *outLen, size_t *outLen,
const wxString& resourceName, const wxString& resourceName,
const wxString& resourceType, const wxChar* resourceType,
WXHINSTANCE instance) WXHINSTANCE instance)
{ {
wxCHECK_MSG( outData && outLen, false, "output pointers can't be NULL" ); wxCHECK_MSG( outData && outLen, false, "output pointers can't be NULL" );
HRSRC hResource = ::FindResource(instance, HRSRC hResource = ::FindResource(instance,
resourceName.t_str(), resourceName.t_str(),
resourceType.t_str()); resourceType);
if ( !hResource ) if ( !hResource )
return false; return false;
@@ -1139,7 +1139,7 @@ wxLoadUserResource(const void **outData,
char * char *
wxLoadUserResource(const wxString& resourceName, wxLoadUserResource(const wxString& resourceName,
const wxString& resourceType, const wxChar* resourceType,
int* pLen, int* pLen,
WXHINSTANCE instance) WXHINSTANCE instance)
{ {