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:
@@ -118,6 +118,8 @@ static const wxChar WX_SECTION[] = wxT("wxWindows");
|
||||
static const wxChar eUSERNAME[] = wxT("UserName");
|
||||
#endif
|
||||
|
||||
WXDLLIMPEXP_DATA_BASE(const wxChar *) wxUserResourceStr = wxT("TEXT");
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@@ -1075,6 +1077,67 @@ bool wxIsDebuggerRunning()
|
||||
#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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user