I first thought to use:
Code: Select all
const wxCharBuffer wxString::mb_str ( const wxMBConv & conv = wxConvLibc ) const
Then I thought to try converting one character at a time, using GetChar. Here is that code:
Code: Select all
#include "ut_bts.h" // 2i
#include "ut_gui.h" // 2j
#include "Settings_Class.h" // 5r
class Settings_Class; // 5s
#include "Wrapper.h" // 5w
#include <wx/buffer.h> // 6
#include <wx/filename.h> // 6
#include <wx/msgdlg.h> // 6
#include <wx/string.h> // 6
.
.
.
// +===========================================================================+
// | ut_gui_Set_Char_Array_to_wxSt |
// | |
// | char array = wxString |
// | |
// | Description: This procedure sets the incoming C-style character array |
// | to the contents of incoming wxString. |
// +===========================================================================+
void ut_gui_Class::ut_gui_Set_Char_Array_to_wxSt
(char ch_array [gd_bts_FILENAME_LENGTH],
wxString wx_St)
{
char ch = ' ';
int i = 0;
int Max_Length = 0;
size_t Length_of_wxSt = 0;
// Initialize the target character array to end-of-string characters.
memset (&ch_array, '\0', gd_bts_FILENAME_LENGTH);
Length_of_wxSt = wx_St.Length (); // <-- GRRR! Execution dies here.
if (Length_of_wxSt == 0) // Incoming wxString is
; // empty. Just leave.
else
{
if (Length_of_wxSt < (size_t) gd_bts_FILENAME_LENGTH) // Set range limit.
Max_Length = Length_of_wxSt;
else
Max_Length = gd_bts_FILENAME_LENGTH;
for (i = 0; i < Max_Length; i++) // Aaaand...copy!
{
ch = (char) wx_St.GetChar (i);
ch_array [i] = ch;
}
}
} // ut_gui_Set_Char_Array_to_wxSt
Length_of_wxSt = wx_St.Length ();
--execution crashes with a "Program Received signal SIGSEGV / Stack Trace is available in the 'Call Stack' Tab" error message. I didn't get any more details except for two links to lines in string.h that I don't understand.
At first I thought wx_St was empty. But no: I have a "Watch" on wx_St showing its value during ut_gui_Set_Char_Array_to_wxSt's execution. When ut_gui_Set_Char_Array_to_wxSt is called, wx_St's value is "F:\Temp\default.csv".
So I tried other things:
* changing wx_St's declaration in the argument list from
wxString wx_St
to
wxString * wx_St
and changed all the affected code appropriately. I still got SIGSEGV errors. I changed the code back, because I didn't want to risk modifying wx_St.
* creating a local wxString temp_wx_St, setting it to wx_St, and using temp_wx_St instead of wx_St. I got the same SIGSEGV error when execution hit the assignment to set temp_wx_St to wx_St.
* setting the local wxString temp_wx_St as follows:
temp_wx_St = wx_St.Capitalize ();
I got the SIGSEGV error.
The more things I tried, the more it seemed like NO MATTER HOW I access the incoming argument wx_St the first time--whether in a .GetChar or .Capitalize or .Clone--I get that SIGSEGV error.
SURELY COPYING A WXSTRING INTO A CHARACTER ARRAY IS NOT A NEW PROBLEM. It should be easier than this!!!
I do not have my heart set on following this approach. What do other people do copy a wxString into a C-type character array?
I am using:
Windows 10, 64 bits
CodeLite v12.0.2
MinGW
Thanks.
Colleen