Optionally return length from wxLoadUserResource().
Add optional length output parameter and also change the return type to "char *" from "wxChar *" to which it apparently was blindly changed just to make this code compile even though this function never returned any strings. Closes #11214. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61977 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -679,7 +679,7 @@ void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y );
|
|||||||
// Returns NULL or newly-allocated memory, so use delete[] to clean up.
|
// Returns NULL or newly-allocated memory, so use delete[] to clean up.
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
extern WXDLLIMPEXP_CORE const wxChar* wxUserResourceStr;
|
extern WXDLLIMPEXP_CORE const wxChar* wxUserResourceStr;
|
||||||
WXDLLIMPEXP_CORE wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
|
WXDLLIMPEXP_CORE char* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr, int* pLen = NULL);
|
||||||
#endif // MSW
|
#endif // MSW
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -108,7 +108,7 @@ bool wxCheckForInterrupt(wxWindow *wnd)
|
|||||||
// Returns NULL or newly-allocated memory, so use delete[] to clean up.
|
// Returns NULL or newly-allocated memory, so use delete[] to clean up.
|
||||||
|
|
||||||
#ifndef __WXMICROWIN__
|
#ifndef __WXMICROWIN__
|
||||||
wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType)
|
char *wxLoadUserResource(const wxString& resourceName, const wxString& resourceType, int* pLen /* = NULL */)
|
||||||
{
|
{
|
||||||
HRSRC hResource = ::FindResource(wxGetInstance(),
|
HRSRC hResource = ::FindResource(wxGetInstance(),
|
||||||
resourceName.wx_str(),
|
resourceName.wx_str(),
|
||||||
@@ -120,15 +120,16 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc
|
|||||||
if ( hData == 0 )
|
if ( hData == 0 )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wxChar *theText = (wxChar *)::LockResource(hData);
|
void *theText = ::LockResource(hData);
|
||||||
if ( !theText )
|
if ( !theText )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Not all compilers put a zero at the end of the resource (e.g. BC++ doesn't).
|
// 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.
|
// so we need to find the length of the resource.
|
||||||
int len = ::SizeofResource(wxGetInstance(), hResource) + 1;
|
int len = ::SizeofResource(wxGetInstance(), hResource);
|
||||||
wxChar *s = new wxChar[len];
|
char *s = new char[len + 1];
|
||||||
wxStrlcpy(s, theText, len);
|
memcpy(s, theText, len);
|
||||||
|
s[len] = '\0'; // NUL-terminate in case the resource itself wasn't
|
||||||
|
|
||||||
// Obsolete in WIN32
|
// Obsolete in WIN32
|
||||||
#ifndef __WIN32__
|
#ifndef __WIN32__
|
||||||
@@ -138,6 +139,9 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc
|
|||||||
// No need??
|
// No need??
|
||||||
// GlobalFree(hData);
|
// GlobalFree(hData);
|
||||||
|
|
||||||
|
if (pLen)
|
||||||
|
*pLen = len;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
#endif // __WXMICROWIN__
|
#endif // __WXMICROWIN__
|
||||||
|
Reference in New Issue
Block a user