Add wxMSW_CONV_LPCTSTR() and related macros and use them in wxBase.
Add macros hiding the ugly casts needed to pass wxStrings to Windows API functions and use them in a couple of places in wxBase to simplify the code. Closes #14338. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71636 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -218,6 +218,21 @@ struct WinStruct : public T
|
||||
};
|
||||
|
||||
|
||||
// Macros for converting wxString to the type expected by API functions.
|
||||
//
|
||||
// Normally it is enough to just use wxString::t_str() which is implicitly
|
||||
// convertible to LPCTSTR, but in some cases an explicit conversion is required.
|
||||
//
|
||||
// In such cases wxMSW_CONV_LPCTSTR() should be used. But if an API function
|
||||
// takes a non-const pointer, wxMSW_CONV_LPTSTR() which casts away the
|
||||
// constness (but doesn't make it possible to really modify the returned
|
||||
// pointer, of course) should be used. And if a string is passed as LPARAM, use
|
||||
// wxMSW_CONV_LPARAM() which does the required ugly reinterpret_cast<> too.
|
||||
#define wxMSW_CONV_LPCTSTR(s) static_cast<const wxChar *>((s).t_str())
|
||||
#define wxMSW_CONV_LPTSTR(s) const_cast<wxChar *>(wxMSW_CONV_LPCTSTR(s))
|
||||
#define wxMSW_CONV_LPARAM(s) reinterpret_cast<LPARAM>(wxMSW_CONV_LPCTSTR(s))
|
||||
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
#include "wx/gdicmn.h"
|
||||
|
@@ -1068,7 +1068,7 @@ static HSZ DDEAtomFromString(const wxString& s)
|
||||
{
|
||||
wxASSERT_MSG( DDEIdInst, wxT("DDE not initialized") );
|
||||
|
||||
HSZ hsz = DdeCreateStringHandle(DDEIdInst, const_cast<wxChar*>(static_cast<const wxChar*>(s.t_str())), DDE_CP);
|
||||
HSZ hsz = DdeCreateStringHandle(DDEIdInst, wxMSW_CONV_LPTSTR(s), DDE_CP);
|
||||
if ( !hsz )
|
||||
{
|
||||
DDELogError(_("Failed to create DDE string"));
|
||||
|
@@ -1057,7 +1057,7 @@ bool wxRegKey::SetValue(const wxString& szValue, const wxString& strValue)
|
||||
m_dwLastError = RegSetValueEx((HKEY) m_hKey,
|
||||
RegValueStr(szValue),
|
||||
(DWORD) RESERVED, REG_SZ,
|
||||
(RegString)static_cast<const TCHAR *>(strValue.t_str()),
|
||||
(RegString)wxMSW_CONV_LPCTSTR(strValue),
|
||||
(strValue.Len() + 1)*sizeof(wxChar));
|
||||
if ( m_dwLastError == ERROR_SUCCESS )
|
||||
return true;
|
||||
|
@@ -857,14 +857,11 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler,
|
||||
// WinCE requires appname to be non null
|
||||
// Win32 allows for null
|
||||
#ifdef __WXWINCE__
|
||||
static_cast<const TCHAR *>(
|
||||
moduleName.t_str()),// application name
|
||||
const_cast<TCHAR *>(static_cast<const TCHAR *>(
|
||||
arguments.t_str())), // arguments
|
||||
moduleName.t_str(), // application name
|
||||
wxMSW_CONV_LPTSTR(arguments), // arguments
|
||||
#else
|
||||
NULL, // application name (use only cmd line)
|
||||
const_cast<TCHAR *>(static_cast<const TCHAR *>(
|
||||
command.t_str())), // full command line
|
||||
wxMSW_CONV_LPTSTR(command), // full command line
|
||||
#endif
|
||||
NULL, // security attributes: defaults for both
|
||||
NULL, // the process and its main thread
|
||||
@@ -872,7 +869,7 @@ long wxExecute(const wxString& cmd, int flags, wxProcess *handler,
|
||||
dwFlags, // process creation flags
|
||||
envBuffer.data(), // environment (may be NULL which is fine)
|
||||
useCwd // initial working directory
|
||||
? const_cast<TCHAR *>(static_cast<const TCHAR *>(env->cwd.t_str()))
|
||||
? wxMSW_CONV_LPTSTR(env->cwd)
|
||||
: NULL, // (or use the same)
|
||||
&si, // startup info (unused here)
|
||||
&pi // process info
|
||||
|
Reference in New Issue
Block a user