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

@@ -104,48 +104,6 @@ bool wxCheckForInterrupt(wxWindow *wnd)
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
// ----------------------------------------------------------------------------