changeset 2961:b9bd130f438a

C++: Step 3 of the std::string transition. Convert the class overrides to use std::string instead of char*. Implement functions that take arrays of strings to std::vector<std::string>. Begin converting dwtestoo to use std::string instead of C style strings. Temporarily rename C style Connect functions to have a C at the end. It isn't clear to me why, but clang is telling me they are ambiguous. Even though the lambda explicitly specifies std::string it can't decide between the std::string or char* versions of the functions.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 23 Feb 2023 15:24:36 +0000
parents 1dabe9c6c67b
children e6072eb914ce
files dw.hpp dwtestoo.cpp
diffstat 2 files changed, 192 insertions(+), 183 deletions(-) [+]
line wrap: on
line diff
--- a/dw.hpp	Thu Feb 16 12:04:52 2023 +0000
+++ b/dw.hpp	Thu Feb 23 15:24:36 2023 +0000
@@ -7,6 +7,7 @@
 #include <dw.h>
 #include <cstring>
 #include <string>
+#include <vector>
 
 // Attempt to support compilers without nullptr type literal
 #if __cplusplus >= 201103L 
@@ -789,21 +790,18 @@
         return classptr->OnConfigure(width, height); }
     static int _OnKeyPress(HWND window, char c, int vk, int state, void *data, char *utf8) {
         Render *classptr = reinterpret_cast<Render *>(data);
+        std::string utf8string = utf8 ? std::string(utf8) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCKeyPress)
             return classptr->_ConnectCKeyPress(c, vk, state, utf8);
-        else if(classptr->_ConnectKeyPress) {
-            std::string utf8string = utf8 ? std::string(utf8) : std::string();
+        else if(classptr->_ConnectKeyPress)
             return classptr->_ConnectKeyPress(c, vk, state, utf8string);
-        }
 #endif
         if(classptr->_ConnectCKeyPressOld)
             return classptr->_ConnectCKeyPressOld(classptr, c, vk, state, utf8);
-        else if(classptr->_ConnectKeyPressOld) {
-            std::string utf8string = utf8 ? std::string(utf8) : std::string();
+        else if(classptr->_ConnectKeyPressOld)
             return classptr->_ConnectKeyPressOld(classptr, c, vk, state, utf8string);
-        }
-        return classptr->OnKeyPress(c, vk, state, utf8); }
+        return classptr->OnKeyPress(c, vk, state, utf8string); }
     static int _OnButtonPress(HWND window, int x, int y, int buttonmask, void *data) {
         Render *classptr = reinterpret_cast<Render *>(data);
 #ifdef DW_LAMBDA
@@ -1000,7 +998,7 @@
         ConfigureConnected = false;
         return FALSE;
     };
-    virtual int OnKeyPress(char c, int vk, int state, char *utf8) {
+    virtual int OnKeyPress(char c, int vk, int state, std::string utf8) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_KEY_PRESS);
         KeyPressConnected = false;
         return FALSE;
@@ -1147,38 +1145,32 @@
     }
     static int _OnChanged(HWND window, int status, char *url, void *data) {
         HTML *classptr = reinterpret_cast<HTML *>(data);
+        std::string utf8string = url ? std::string(url) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCChanged)
             return classptr->_ConnectCChanged(status, url);
-        else if(classptr->_ConnectChanged) {
-            std::string utf8string = url ? std::string(url) : std::string();
+        else if(classptr->_ConnectChanged)
             return classptr->_ConnectChanged(status, utf8string);
-        }
 #endif
         if(classptr->_ConnectCChangedOld)
             return classptr->_ConnectCChangedOld(classptr, status, url);
-        else if(classptr->_ConnectChangedOld) {
-            std::string utf8string = url ? std::string(url) : std::string();
+        else if(classptr->_ConnectChangedOld)
             return classptr->_ConnectChangedOld(classptr, status, utf8string);
-        }
-        return classptr->OnChanged(status, url); }
+        return classptr->OnChanged(status, utf8string); }
     static int _OnResult(HWND window, int status, char *result, void *scriptdata, void *data) {
         HTML *classptr = reinterpret_cast<HTML *>(data);
+        std::string utf8string = result ? std::string(result) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCResult)
             return classptr->_ConnectResult(status, result, scriptdata);
-        else if(classptr->_ConnectResult) {
-            std::string utf8string = result ? std::string(result) : std::string();
+        else if(classptr->_ConnectResult)
             return classptr->_ConnectResult(status, utf8string, scriptdata);
-        }
 #endif
         if(classptr->_ConnectCResultOld)
             return classptr->_ConnectCResultOld(classptr, status, result, scriptdata);
-        else if(classptr->_ConnectResultOld) {
-            std::string utf8string = result ? std::string(result) : std::string();
+        else if(classptr->_ConnectResultOld)
             return classptr->_ConnectResultOld(classptr, status, utf8string, scriptdata);
-        }
-        return classptr->OnResult(status, result, scriptdata); }
+        return classptr->OnResult(status, utf8string, scriptdata); }
 public:
     // Constructors
     HTML(unsigned long id) { SetHWND(dw_html_new(id)); Setup(); }
@@ -1195,7 +1187,7 @@
     int Raw(std::string buffer) { return dw_html_raw(hwnd, buffer.c_str()); }
     int URL(std::string url) { return dw_html_url(hwnd, url.c_str()); }
 #ifdef DW_LAMBDA
-    void ConnectChanged(std::function<int(int, char *)> userfunc)
+    void ConnectChangedC(std::function<int(int, char *)> userfunc)
     { 
         _ConnectCChanged = userfunc;
         if(!ChangedConnected) {
@@ -1229,7 +1221,7 @@
         }
     }
 #ifdef DW_LAMBDA
-    void ConnectResult(std::function<int(int, char *, void *)> userfunc)
+    void ConnectResultC(std::function<int(int, char *, void *)> userfunc)
     {
         _ConnectCResult = userfunc;
         if(!ResultConnected) {
@@ -1265,12 +1257,12 @@
 protected:
     // Our signal handler functions to be overriden...
     // If they are not overridden and an event is generated, remove the unused handler
-    virtual int OnChanged(int status, char *url) {
+    virtual int OnChanged(int status, std::string url) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_CHANGED); 
         ChangedConnected = false;
         return FALSE;
     }
-    virtual int OnResult(int status, char *result, void *scriptdata) {
+    virtual int OnResult(int status, std::string result, void *scriptdata) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_HTML_RESULT);
         ResultConnected = false;
         return FALSE;
@@ -1337,11 +1329,33 @@
     int Count() { return dw_listbox_count(hwnd); }
     void Delete(int index) { dw_listbox_delete(hwnd, index); }
     void GetListText(unsigned int index, char *buffer, unsigned int length) { dw_listbox_get_text(hwnd, index, buffer, length); }
+    std::string GetListText(unsigned int index) {
+        int length = 1025;
+        char *buffer = (char *)alloca(length);
+
+        if(buffer) {
+            memset(buffer, 0, length);
+            dw_listbox_get_text(hwnd, index, buffer, length);
+            return std::string(buffer);
+        }
+        return std::string();
+    }
     void SetListText(unsigned int index, char *buffer) { dw_listbox_set_text(hwnd, index, buffer); }
     void SetListText(unsigned int index, std::string buffer) { dw_listbox_set_text(hwnd, index, buffer.c_str()); }
     void Insert(const char *text, int pos) { dw_listbox_insert(hwnd, text, pos); }
     void Insert(std::string text, int pos) { dw_listbox_insert(hwnd, text.c_str(), pos); }
     void ListAppend(char **text, int count) { dw_listbox_list_append(hwnd, text, count); }
+    void ListAppend(std::vector<std::string> text) {
+        int count = (int)text.size();
+        const char **ctext = (const char **)alloca(sizeof(char *) * count);
+
+        if(count > 0 && ctext) {
+            for(int z=0; z<count; z++) {
+                ctext[z] = text[z].c_str();
+            }
+            dw_listbox_list_append(hwnd, (char **)ctext, count);
+        }
+    }
     void Select(int index, int state) { dw_listbox_select(hwnd, index, state); }
     int Selected() { return dw_listbox_selected(hwnd); }
     int Selected(int where) { return dw_listbox_selected_multi(hwnd, where); }
@@ -1533,6 +1547,16 @@
     void Clear() { dw_mle_clear(hwnd); }
     void Delete(int startpoint, int length) { dw_mle_delete(hwnd, startpoint, length); }
     void Export(char *buffer, int startpoint, int length) { dw_mle_export(hwnd, buffer, startpoint, length); }
+    std::string Export(int startpoint, int length) {
+        char *buffer = (char *)alloca(length + 1);
+
+        if(buffer) {
+            memset(buffer, 0, length + 1);
+            dw_mle_export(hwnd, buffer, startpoint, length);
+            return std::string(buffer);
+        }
+        return std::string();
+    }
     int Import(const char *buffer, int startpoint) { return dw_mle_import(hwnd, buffer, startpoint); }
     int Import(std::string buffer, int startpoint) { return dw_mle_import(hwnd, buffer.c_str(), startpoint); }
     void GetSize(unsigned long *bytes, unsigned long *lines) { dw_mle_get_size(hwnd, bytes, lines); }
@@ -1644,39 +1668,33 @@
     int (*_ConnectItemContextOld)(ObjectView *, std::string, int, int, void *);
     static int _OnItemSelect(HWND window, HTREEITEM item, char *text, void *data, void *itemdata) {
         ObjectView *classptr = reinterpret_cast<ObjectView *>(data);
+        std::string utf8string = text ? std::string(text) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCItemSelect)
             return classptr->_ConnectCItemSelect(item, text, itemdata);
-        else if(classptr->_ConnectItemSelect) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemSelect)
             return classptr->_ConnectItemSelect(item, utf8string, itemdata);
-        }
 #endif
         if(classptr->_ConnectItemSelectOld)
             return classptr->_ConnectItemSelectOld(classptr, item, text, itemdata);
-        else if(classptr->_ConnectItemSelectOld) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemSelectOld)
             return classptr->_ConnectItemSelectOld(classptr, item, utf8string, itemdata);
-        }
-        return classptr->OnItemSelect(item, text, itemdata);
+        return classptr->OnItemSelect(item, utf8string, itemdata);
     }
     static int _OnItemContext(HWND window, char *text, int x, int y, void *data, void *itemdata) {
         ObjectView *classptr = reinterpret_cast<ObjectView *>(data);
+        std::string utf8string = text ? std::string(text) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCItemContext)
             return classptr->_ConnectCItemContext(text, x, y, itemdata);
-        else if(classptr->_ConnectItemContext) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemContext)
             return classptr->_ConnectItemContext(utf8string, x, y, itemdata);
-        }
 #endif
         if(classptr->_ConnectCItemContextOld)
             return classptr->_ConnectCItemContextOld(classptr, text, x, y, itemdata);
-        else if(classptr->_ConnectItemContextOld) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemContextOld)
             return classptr->_ConnectItemContextOld(classptr, utf8string, x, y, itemdata);
-        }
-        return classptr->OnItemContext(text, x, y, itemdata);
+        return classptr->OnItemContext(utf8string, x, y, itemdata);
     }
 protected:
     void SetupObjectView() {
@@ -1705,19 +1723,19 @@
     }
     // Our signal handler functions to be overriden...
     // If they are not overridden and an event is generated, remove the unused handler
-    virtual int OnItemSelect(HTREEITEM item, char *text, void *itemdata) {
+    virtual int OnItemSelect(HTREEITEM item, std::string text, void *itemdata) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_SELECT);
         ItemSelectConnected = false;
         return FALSE;
     }
-    virtual int OnItemContext(char *text, int x, int y, void *itemdata) {
+    virtual int OnItemContext(std::string text, int x, int y, void *itemdata) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_CONTEXT);
         ItemContextConnected = false;
         return FALSE;
     }
 public:
 #ifdef DW_LAMBDA
-    void ConnectItemSelect(std::function<int(HTREEITEM, char *, void *)> userfunc)
+    void ConnectItemSelectC(std::function<int(HTREEITEM, char *, void *)> userfunc)
     {
         _ConnectCItemSelect = userfunc;
         if(!ItemSelectConnected) {
@@ -1751,7 +1769,7 @@
         }
     }
 #ifdef DW_LAMBDA
-    void ConnectItemContext(std::function<int(char *, int, int, void *)> userfunc)
+    void ConnectItemContextC(std::function<int(char *, int, int, void *)> userfunc)
     {
         _ConnectCItemContext = userfunc;
         if(!ItemContextConnected) {
@@ -1800,21 +1818,18 @@
     int (*_ConnectColumnClickOld)(Containers *, int);
     static int _OnItemEnter(HWND window, char *text, void *data, void *itemdata) {
         Containers *classptr = reinterpret_cast<Containers *>(data);
+        std::string utf8string = text ? std::string(text) : std::string();
 #ifdef DW_LAMBDA
         if(classptr->_ConnectCItemEnter)
             return classptr->_ConnectCItemEnter(text, itemdata);
-        else if(classptr->_ConnectItemEnter) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemEnter)
             return classptr->_ConnectItemEnter(utf8string, itemdata);
-        }
 #endif
         if(classptr->_ConnectCItemEnterOld)
             return classptr->_ConnectCItemEnterOld(classptr, text, itemdata);
-        else if(classptr->_ConnectItemEnterOld) {
-            std::string utf8string = text ? std::string(text) : std::string();
+        else if(classptr->_ConnectItemEnterOld)
             return classptr->_ConnectItemEnterOld(classptr, utf8string, itemdata);
-        }
-        return classptr->OnItemEnter(text, itemdata);
+        return classptr->OnItemEnter(utf8string, itemdata);
     }
     static int _OnColumnClick(HWND window, int column, void *data) {
         Containers *classptr = reinterpret_cast<Containers *>(data);
@@ -1853,7 +1868,7 @@
     }
     // Our signal handler functions to be overriden...
     // If they are not overridden and an event is generated, remove the unused handler
-    virtual int OnItemEnter(char *text, void *itemdata) {
+    virtual int OnItemEnter(std::string text, void *itemdata) {
         dw_signal_disconnect_by_name(hwnd, DW_SIGNAL_ITEM_ENTER);
         ItemEnterConnected = false;
         return FALSE;
@@ -1879,8 +1894,16 @@
     void DeleteRow(void *data) { dw_container_delete_row_by_data(hwnd, data); }
     void Insert() { dw_container_insert(hwnd, allocpointer, allocrowcount); }
     void Optimize() { dw_container_optimize(hwnd); }
-    char *QueryNext(unsigned long flags) { return dw_container_query_next(hwnd, flags); }
-    char *QueryStart(unsigned long flags) { return dw_container_query_start(hwnd, flags); }
+    char *QueryCNext(unsigned long flags) { return dw_container_query_next(hwnd, flags); }
+    char *QueryCStart(unsigned long flags) { return dw_container_query_start(hwnd, flags); }
+    std::string QueryNext(unsigned long flags) {
+        char *retval = dw_container_query_next(hwnd, flags);
+        return retval ? std::string(retval) : std::string();
+    }
+    std::string QueryStart(unsigned long flags) {
+        char *retval = dw_container_query_start(hwnd, flags);
+        return retval ? std::string(retval) : std::string();
+    }
     void Scroll(int direction, long rows) { dw_container_scroll(hwnd, direction, rows); }
     void SetColumnWidth(int column, int width) { dw_container_set_column_width(hwnd, column, width); }
     void SetRowData(int row, void *data) { dw_container_set_row_data(allocpointer, row, data); }
@@ -1888,7 +1911,7 @@
     void SetRowTitle(int row, const std::string title) { dw_container_set_row_title(allocpointer, row, title.c_str()); }
     void SetStripe(unsigned long oddcolor, unsigned long evencolor) { dw_container_set_stripe(hwnd, oddcolor, evencolor); }
 #ifdef DW_LAMBDA
-    void ConnectItemEnter(std::function<int(char *, void *)> userfunc)
+    void ConnectItemEnterC(std::function<int(char *, void *)> userfunc)
     {
         _ConnectCItemEnter = userfunc;
         if(!ItemEnterConnected) {
@@ -1974,6 +1997,24 @@
       SetupObjectView(); SetupContainer();
       return retval;
     }    
+    int Setup(std::vector<unsigned long> flags, std::vector<std::string> titles) {
+      int count = (int)flags.size();
+
+      // Use the smallest of the two lists
+      if(count > titles.size()) {
+          count = (int)titles.size();
+      }
+      // Convert our vectors into a arrays of unsigned long and C strings
+      const char **ctitles = (const char **)alloca(sizeof(char *) * count); 
+      unsigned long *cflags = (unsigned long *)alloca(sizeof(unsigned long) * count);
+      for(int z=0; z<count; z++) {
+          ctitles[z] = titles[z].c_str();
+          cflags[z] = flags[z];
+      }
+      int retval = dw_filesystem_setup(hwnd, cflags, (char **)ctitles, count);
+      SetupObjectView(); SetupContainer();
+      return retval;
+    }    
     void ChangeFile(int row, const char *filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename, icon); }
     void ChangeFile(int row, std::string filename, HICN icon) { dw_filesystem_change_file(hwnd, row, filename.c_str(), icon); }
     void ChangeItem(int column, int row, void *data) { dw_filesystem_change_item(hwnd, column, row, data); }
--- a/dwtestoo.cpp	Thu Feb 16 12:04:52 2023 +0000
+++ b/dwtestoo.cpp	Thu Feb 23 15:24:36 2023 +0000
@@ -413,51 +413,50 @@
         return combobox;
     }
 
-    unsigned long ComboboxColor(const char *colortext) {
+    unsigned long ComboboxColor(std::string colortext) {
         unsigned long color = DW_CLR_DEFAULT;
 
-        if(strcmp(colortext, "DW_CLR_BLACK") == 0)
+        if(colortext.compare("DW_CLR_BLACK") == 0)
             color = DW_CLR_BLACK;
-        else if(strcmp(colortext, "DW_CLR_DARKRED") == 0)
+        else if(colortext.compare("DW_CLR_DARKRED") == 0)
             color = DW_CLR_DARKRED;
-        else if(strcmp(colortext, "DW_CLR_DARKGREEN") == 0)
+        else if(colortext.compare("DW_CLR_DARKGREEN") == 0)
             color = DW_CLR_DARKGREEN;
-        else if(strcmp(colortext, "DW_CLR_BROWN") == 0)
+        else if(colortext.compare("DW_CLR_BROWN") == 0)
             color = DW_CLR_BROWN;
-        else if(strcmp(colortext, "DW_CLR_DARKBLUE") == 0)
+        else if(colortext.compare("DW_CLR_DARKBLUE") == 0)
             color = DW_CLR_DARKBLUE;
-        else if(strcmp(colortext, "DW_CLR_DARKPINK") == 0)
+        else if(colortext.compare("DW_CLR_DARKPINK") == 0)
             color = DW_CLR_DARKPINK;
-        else if(strcmp(colortext, "DW_CLR_DARKCYAN") == 0)
+        else if(colortext.compare("DW_CLR_DARKCYAN") == 0)
             color = DW_CLR_DARKCYAN;
-        else if(strcmp(colortext, "DW_CLR_PALEGRAY") == 0)
+        else if(colortext.compare("DW_CLR_PALEGRAY") == 0)
             color = DW_CLR_PALEGRAY;
-        else if(strcmp(colortext, "DW_CLR_DARKGRAY") == 0)
+        else if(colortext.compare("DW_CLR_DARKGRAY") == 0)
             color = DW_CLR_DARKGRAY;
-        else if(strcmp(colortext, "DW_CLR_RED") == 0)
+        else if(colortext.compare("DW_CLR_RED") == 0)
             color = DW_CLR_RED;
-        else if(strcmp(colortext, "DW_CLR_GREEN") == 0)
+        else if(colortext.compare("DW_CLR_GREEN") == 0)
             color = DW_CLR_GREEN;
-        else if(strcmp(colortext, "DW_CLR_YELLOW") == 0)
+        else if(colortext.compare("DW_CLR_YELLOW") == 0)
             color = DW_CLR_YELLOW;
-        else if(strcmp(colortext, "DW_CLR_BLUE") == 0)
+        else if(colortext.compare("DW_CLR_BLUE") == 0)
             color = DW_CLR_BLUE;
-        else if(strcmp(colortext, "DW_CLR_PINK") == 0)
+        else if(colortext.compare("DW_CLR_PINK") == 0)
             color = DW_CLR_PINK;
-        else if(strcmp(colortext, "DW_CLR_CYAN") == 0)
+        else if(colortext.compare("DW_CLR_CYAN") == 0)
             color = DW_CLR_CYAN;
-        else if(strcmp(colortext, "DW_CLR_WHITE") == 0)
+        else if(colortext.compare("DW_CLR_WHITE") == 0)
             color = DW_CLR_WHITE;
 
         return color;
     }
 
-    void MLESetFont(DW::MLE *mle, int fontsize, char *fontname) {
-        char font[151] = {0};
-
-        if(fontname)
-            snprintf(font, 150, "%d.%s", fontsize, fontname);
-        mle->SetFont(fontname ? font : NULL);
+    void MLESetFont(DW::MLE *mle, int fontsize, std::string fontname) {
+        if(fontname.size() && fontsize > 0) {
+            mle->SetFont(std::to_string(fontsize) + "." + fontname);
+        }
+        mle->SetFont(NULL);
     }
 
     // Thread and Event functions
@@ -756,11 +755,10 @@
         });
 
         copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int {
-            char *test = copypastefield->GetCText();
+            std::string test = copypastefield->GetText();
 
-            if(test) {
+            if(test.size()) {
                 this->app->SetClipboard(test);
-                this->app->Free(test);
             }
             entryfield->SetFocus();
             return TRUE; 
@@ -768,10 +766,9 @@
 
         pastebutton->ConnectClicked([this, copypastefield]() -> int 
         {
-            char *test = this->app->GetCClipboard();
-            if(test) {
+            std::string test = this->app->GetClipboard();
+            if(test.size()) {
                 copypastefield->SetText(test);
-                this->app->Free(test);
             }
             return TRUE;
         });
@@ -917,15 +914,10 @@
             image = new DW::Pixmap(render1, "~/test");
         if(!image || !image->GetHPIXMAP())
         {
-            char *appdir = app->GetCDir();
-            char pathbuff[1025] = {0};
-            int pos = (int)strlen(appdir);
-            
-            strncpy(pathbuff, appdir, 1024);
-            pathbuff[pos] = DW_DIR_SEPARATOR;
-            pos++;
-            strncpy(&pathbuff[pos], "test", 1024-pos);
-            image = new DW::Pixmap(render1, pathbuff);
+            std::string appdir = app->GetDir();
+            appdir.append(std::string(1, DW_DIR_SEPARATOR));
+            appdir.append("test");
+            image = new DW::Pixmap(render1, appdir);
         }
         if(image)
             image->SetTransparentColor(DW_CLR_WHITE);
@@ -1182,21 +1174,19 @@
             notebookbox->PackStart(tree_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1);
 
             // set up our signal trappers...
-            tree->ConnectItemContext([this, tree_status](char *text, int x, int y, void *data) -> int
+            tree->ConnectItemContext([this, tree_status](std::string text, int x, int y, void *data) -> int
             {
-                char buf[201] = {0};
                 DW::Menu *popupmenu = ItemContextMenu(tree_status, "Item context menu clicked.");
-
-                snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d", text, x, y);
+                std::string buf = "DW_SIGNAL_ITEM_CONTEXT: Text: " + text + " x: " + std::to_string(x) + " y: " + std::to_string(y);
                 tree_status->SetText(buf);
                 popupmenu->Popup(this, x, y);
                 return FALSE;
             });
-            tree->ConnectItemSelect([tree_status](HTREEITEM item, char *text, void *itemdata)
+            tree->ConnectItemSelect([tree_status](HTREEITEM item, std::string text, void *itemdata)
             {
-                char buf[201] = {0};
-
-                snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x", DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
+                std::string sitem = std::to_string(DW_POINTER_TO_UINT(item));
+                std::string sitemdata = std::to_string(DW_POINTER_TO_UINT(itemdata));
+                std::string buf = "DW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata;
                 tree_status->SetText(buf);
                 return FALSE;
             });
@@ -1211,10 +1201,11 @@
             tree->Change(t2, "tree folder 2", foldericon);
             tree->SetData(t2, DW_INT_TO_POINTER(100));
             tree->Expand(t1);
-            char *title = tree->GetCTitle(t1);
-            this->app->Debug("t1 title \"%s\" data %d t2 data %d\n", title, DW_POINTER_TO_INT(tree->GetData(t1)),
-                     DW_POINTER_TO_INT(tree->GetData(t2)));
-            this->app->Free(title);
+            int t1data = DW_POINTER_TO_INT(tree->GetData(t1));
+            int t2data = DW_POINTER_TO_INT(tree->GetData(t2));
+            std::string message = "t1 title \"" + tree->GetTitle(t1) + "\" data " + std::to_string(t1data) + " t2 data " + std::to_string(t2data) + "\n";
+
+            this->app->Debug(message);
         }
         else
         {
@@ -1278,15 +1269,16 @@
         DW::StatusText *container_status = new DW::StatusText();
         notebookbox->PackStart(container_status, 100, DW_SIZE_AUTO, TRUE, FALSE, 1);
 
-        const char *titles[] = { "Type", "Size", "Time", "Date" };
-        unsigned long flags[4] = {  DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
-                                    DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
-                                    DW_CFA_TIME | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
-                                    DW_CFA_DATE | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR };
+        std::vector<std::string> titles = { "Type", "Size", "Time", "Date" };
+        std::vector<unsigned long> flags = {
+            DW_CFA_BITMAPORICON | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
+            DW_CFA_ULONG | DW_CFA_RIGHT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
+            DW_CFA_TIME | DW_CFA_CENTER | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR,
+            DW_CFA_DATE | DW_CFA_LEFT | DW_CFA_HORZSEPARATOR | DW_CFA_SEPARATOR };
 
 
         container->SetColumnTitle("Test");
-        container->Setup(flags, titles, 4);
+        container->Setup(flags, titles);
         container->SetStripe(DW_CLR_DEFAULT, DW_CLR_DEFAULT);
         container->Alloc(3);
 
@@ -1348,42 +1340,37 @@
         container_mle->SetCursor(mle_point);
 
         // connect our event trappers...
-        container->ConnectItemEnter([container_status](char *text, void *itemdata) -> int
+        container->ConnectItemEnter([container_status](std::string text, void *itemdata) -> int
         {
-            char buf[201] = {0};
-
-            snprintf(buf, 200, "DW_SIGNAL_ITEM_ENTER: Text: %s Itemdata: %x", text, DW_POINTER_TO_UINT(itemdata));
+            std::string buf = "DW_SIGNAL_ITEM_ENTER: Text: " + text + "Itemdata: " + std::to_string(DW_POINTER_TO_UINT(itemdata));
             container_status->SetText(buf);
             return FALSE;
         });
 
-        container->ConnectItemContext([this, container_status](char *text, int x, int y, void *itemdata) -> int
+        container->ConnectItemContext([this, container_status](std::string text, int x, int y, void *itemdata) -> int
         {
-            char buf[201] = {0};
             DW::Menu *popupmenu = ItemContextMenu(container_status, "Item context menu clicked.");
+            std::string buf = "DW_SIGNAL_ITEM_CONTEXT: Text: " + text + " x: " + std::to_string(x) + " y: " + 
+                std::to_string(y) + " Itemdata: " + std::to_string(DW_POINTER_TO_UINT(itemdata));
 
-            snprintf(buf, 200, "DW_SIGNAL_ITEM_CONTEXT: Text: %s x: %d y: %d Itemdata: %x", text, x, y, DW_POINTER_TO_UINT(itemdata));
             container_status->SetText(buf);
             popupmenu->Popup(this, x, y);
             return FALSE;
         });
 
-        container->ConnectItemSelect([this, container_mle, container, container_status](HTREEITEM item, char *text, void *itemdata) -> int
+        container->ConnectItemSelect([this, container_mle, container, container_status](HTREEITEM item, std::string text, void *itemdata) -> int
         {
-            char buf[201] = {0};
-
-            snprintf(buf, 200, "DW_SIGNAL_ITEM_SELECT:Item: %x Text: %s Itemdata: %x",
-                    DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
+            std::string sitemdata = std::to_string(DW_POINTER_TO_UINT(itemdata));
+            std::string sitem = std::to_string(DW_POINTER_TO_UINT(item));
+            std::string buf = "DW_SIGNAL_ITEM_SELECT:Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata;
             container_status->SetText(buf);
-            snprintf(buf, 200, "\r\nDW_SIGNAL_ITEM_SELECT: Item: %x Text: %s Itemdata: %x\r\n",
-                    DW_POINTER_TO_UINT(item), text, DW_POINTER_TO_UINT(itemdata));
+            buf = "\r\nDW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " +  sitemdata + "\r\n";
             this->mle_point = container_mle->Import(buf, mle_point);
-            char *str = container->QueryStart(DW_CRA_SELECTED);
-            while(str)
+            std::string str = container->QueryStart(DW_CRA_SELECTED);
+            while(str.size())
             {
-                snprintf(buf, 200, "Selected: %s\r\n", str);
+                std::string buf = "Selected: " + str + "%s\r\n";
                 mle_point = container_mle->Import(buf, mle_point);
-                this->app->Free(str);
                 str = container->QueryNext(DW_CRA_SELECTED);
             }
             // Make the last inserted point the cursor location
@@ -1426,17 +1413,14 @@
 
         mlefore->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int
         {
-            char colortext[101] = {0};
             ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT;
 
-            mlefore->GetListText(pos, colortext, 100);
+            std::string colortext = mlefore->GetListText(pos);
             fore = ComboboxColor(colortext);
-            char *text = mleback->GetCText();
+            std::string text = mleback->GetText();
 
-            if(text && *text)
-            {
+            if(text.size()) {
                 back = ComboboxColor(text);
-                this->app->Free(text);
             }
             container_mle->SetColor(fore, back);
             return FALSE;
@@ -1444,17 +1428,14 @@
 
         mleback->ConnectListSelect([this, mlefore, mleback, container_mle](unsigned int pos) -> int
         {
-            char colortext[101] = {0};
             ULONG fore = DW_CLR_DEFAULT, back = DW_CLR_DEFAULT;
 
-            mleback->GetListText(pos, colortext, 100);
+            std::string colortext = mleback->GetListText(pos);
             back = ComboboxColor(colortext);
-            char *text = mlefore->GetCText();
+            std::string text = mlefore->GetText();
 
-            if(text && *text)
-            {
+            if(text.size()) {
                 fore = ComboboxColor(text);
-                this->app->Free(text);
             }
             container_mle->SetColor(fore, back);
             return FALSE;
@@ -1462,21 +1443,17 @@
 
         fontname->ConnectListSelect([this, fontname, fontsize, container_mle](unsigned int pos) -> int
         {
-            char font[101] = {0};
-
-            fontname->GetListText(pos, font, 100);
-            MLESetFont(container_mle, (int)fontsize->GetPos(), strcmp(font, "Default") == 0 ? NULL : font);
+            std::string font = fontname->GetListText(pos);
+            MLESetFont(container_mle, (int)fontsize->GetPos(), font.compare("Default") == 0 ? NULL : font);
             return FALSE;
         });
 
         fontsize->ConnectValueChanged([this, fontname, container_mle](int size) -> int
         {
-            char *font = fontname->GetCText();
+            std::string font = fontname->GetText();
 
-            if(font)
-            {
-                MLESetFont(container_mle, size, strcmp(font, "Default") == 0 ? NULL : font);
-                this->app->Free(font);
+            if(font.size()) {
+                MLESetFont(container_mle, size, font.compare("Default") == 0 ? NULL : font);
             }
             else
                 MLESetFont(container_mle, size, NULL);
@@ -1697,12 +1674,13 @@
 
             button = new DW::Button("Run");
             hbox->PackStart(button, FALSE, FALSE, 0);
-            button->ConnectClicked([this, javascript, html]() -> int
+            button->ConnectClicked([javascript, html]() -> int
             {
-                char *script = javascript->GetCText();
+                std::string script = javascript->GetText();
 
-                html->JavascriptRun(script);
-                this->app->Free(script);
+                if(script.size()) {
+                    html->JavascriptRun(script);
+                }
                 return FALSE;
             });
             javascript->ClickDefault(button);
@@ -1713,26 +1691,20 @@
             notebookbox->PackStart(htmlstatus, 100, DW_SIZE_AUTO, TRUE, FALSE, 1);
 
             // Connect the signal handlers
-            html->ConnectChanged([htmlstatus](int status, char *url) -> int
+            html->ConnectChanged([htmlstatus](int status, std::string url) -> int
             {
-                const char *statusnames[] = { "none", "started", "redirect", "loading", "complete", NULL };
+                std::vector<std::string> statusnames = { "none", "started", "redirect", "loading", "complete" };
 
-                if(htmlstatus && url && status < 5)
-                {
-                    int length = (int)strlen(url) + (int)strlen(statusnames[status]) + 10;
-                    char *text = (char *)calloc(1, length+1);
-
-                    snprintf(text, length, "Status %s: %s", statusnames[status], url);
-                    htmlstatus->SetText(text);
-                    free(text);
+                if(htmlstatus && status < 5) {
+                    htmlstatus->SetText("Status " + statusnames[status] + ": " + url);
                 }
                 return FALSE;
             });
 
-            html->ConnectResult([this](int status, char *result, void *script_data)
+            html->ConnectResult([this](int status, std::string result, void *script_data)
             {
                 this->app->MessageBox("Javascript Result", DW_MB_OK | (status ? DW_MB_ERROR : DW_MB_INFORMATION),
-                              result ? result : "Javascript result is not a string value");
+                              result.size() ? result : "Javascript result is not a string value");
                 return TRUE;
             });
         }
@@ -1844,12 +1816,12 @@
         // also check the appropriate platform subfolder
         if(!foldericon)
         {
-            strncpy(foldericonpath, PLATFORMFOLDER "folder", 1024);
+            foldericonpath = std::string(PLATFORMFOLDER) + "folder";
             foldericon = app->LoadIcon(foldericonpath);
         }
         if(!fileicon)
         {
-            strncpy(fileiconpath, PLATFORMFOLDER "file", 1024);
+            fileiconpath = std::string(PLATFORMFOLDER) + "file";
             fileicon = app->LoadIcon(fileiconpath);
         }
 #endif
@@ -1857,21 +1829,17 @@
         // Finally try from the platform application directory
         if(!foldericon && !fileicon)
         {
-            char *appdir = app->GetCDir();
-            char pathbuff[1025] = {0};
-            int pos = (int)strlen(appdir);
-
-            strncpy(pathbuff, appdir, 1024);
-            pathbuff[pos] = DW_DIR_SEPARATOR;
-            pos++;
-            strncpy(&pathbuff[pos], "folder", 1024-pos);
-            foldericon = app->LoadIcon(pathbuff);
+            std::string appdir = app->GetDir();
+            
+            appdir.append(std::string(1, DW_DIR_SEPARATOR));
+            std::string folderpath = appdir + "folder";
+            foldericon = app->LoadIcon(folderpath);
             if(foldericon)
-                strncpy(foldericonpath, pathbuff, 1025);
-            strncpy(&pathbuff[pos], "file", 1024-pos);
-            fileicon = app->LoadIcon(pathbuff);
+                foldericonpath = folderpath;
+            std::string filepath = appdir + "file";
+            fileicon = app->LoadIcon(filepath);
             if(fileicon)
-                strncpy(fileiconpath, pathbuff, 1025);
+                fileiconpath = filepath;
         }
 
         DW::Notebook *notebook = new DW::Notebook();
@@ -1982,8 +1950,8 @@
     // Miscellaneous
     int menu_enabled = TRUE;
     HICN fileicon, foldericon;
-    char fileiconpath[1025] = "file";
-    char foldericonpath[1025] = "folder";
+    std::string fileiconpath = "file";
+    std::string foldericonpath = "folder";
 
 
     int OnDelete() override {