C++ odd text behavior - random garbage text

After I reinstalled my OS (2008 Server) I then noticed that there's something odd going on within my program.

Here's the link to part of the source http://phantomworksstudios.com/cpp/ss/sof-odd.h

Here's the code first:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    //custom-data.h

    class INI_{    
        
      public:
        const char* error;
        stringstream CharToStr2;
        Layout layout;      
        Settings settings;  
        string file; 
 
        int OpenFile(string open_file){
          CharToStr2.str("");
          ifstream SSMAIN_FILE_SETTINGS; 
          CharToStr2<<open_file;
          cout<<"CharToStr: "<<CharToStr2<<endl;
          cout<<"CharToStr.str(): "<<CharToStr2.str()<<endl; 
          cout<<"CharToStr.str.c_str(): "<<CharToStr2.str().c_str()<<endl;
       
          SSMAIN_FILE_SETTINGS.open(CharToStr2.str().c_str());
          if(!SSMAIN_FILE_SETTINGS){
            CharToStr2<<" is currupt or not found!. Loading default configuration!";
            cout<<"STRING1:"<<CharToStr2<<endl<<endl;
            cout<<"STRING2:"<<CharToStr2.str()<<endl<<endl;
            cout<<"STRING3:"<<CharToStr2.str().c_str()<<endl<<endl;
            error=CharToStr2.str().c_str(); 
            cout<<"ERROR:"<<error<<endl;   
          }
          cout <<"CLASS INI_: "<<SSMAIN_FILE_SETTINGS<<" : "<<file<<endl<<endl;
        }
    };

INI_ SourceStudioConfiguration;


//procedures.h

//more code before this
    case WM_CREATE:  
        SSMAIN_EXPLORERWINDOW_MENU=LoadMenu(SSMAIN_HINSTANCE,MAKEINTRESOURCE(ID_EXPLORER_MENU));
        SourceStudioConfiguration.layout.cx=0;   
        User_Buffer=32767;
        OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken);
        GetUserProfileDirectory(hToken,InfoBuf,&User_Buffer);
        User_Path=InfoBuf;
//      cout<<InfoBuf<<endl<<endl;
        CharToStr<<InfoBuf<<"\\Source Studio\\preference.ini";
        preference=CharToStr.str();
        cout<<User_Path<<" : "<<preference<<endl<<endl;
//      SourceStudioConfiguration.file=preference;
        SourceStudioConfiguration.OpenFile(preference);
        cout<<"CREATE:"<<SourceStudioConfiguration.error<<endl<<endl;                
        cout<<"Class File"<<SourceStudioConfiguration.file<<endl<<endl;
        hbmPWSBUTTON = (HBITMAP)LoadBitmap(hInst_PWSBUTTON,           
        MAKEINTRESOURCE(IMG_PWS_BUTTON));
        cout<<"Load PWS Bitmap: "<<hbmPWSBUTTON<<endl;
        hbmPWSCommandOVERVIEW=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB,                                                
        MAKENTRESOURCE(IMG_PWS_COMMAND_OVERVIEW));
        hbmPWSCommandDOCUMENT=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB,   MAKEINTRESOURCE(IMG_PWS_COMMAND_DOCUMENT));
        hbmPWSCommandNEWFILE=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB, MAKEINTRESOURCE(IMG_PWS_COMMAND_NEWFILE));
        hbmPWSCommandCLOSE=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB,  MAKEINTRESOURCE(IMG_PWS_COMMAND_CLOSE));
        cout<<"CREATE:"<<SourceStudioConfiguration.error<<endl<<endl;
        cout<<"Load PWS Command Toolbar Bitmap: "<<hbmPWSCommandOVERVIEW<<endl;
        cout<<"CREATE 277:"<<SourceStudioConfiguration.error<<endl<<endl;
        SSMAIN_REBARWINDOW=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,REBARCLASSNAME,NULL,            WS_CHILD|WS_BORDER|RBS_VARHEIGHT|TBS_HORZ|RBS_BANDBORDERS|CCS_NODIVIDER|CCS_NOPARENTALIGN,0,0,0,0,hwnd, NULL, 0, 0);     
        SSMAIN_EXPLORERWINDOW=CreateWindowEx(WS_EX_TRANSPARENT,"button",NULL, BS_GROUPBOX|WS_CHILD,0,79,150,SSMAIN_HEIGHT-157,hwnd, (HMENU)SSMAIN_EXPLORERWINDOW_MENU, SSMAIN_EXPLORERBAR_HINSTANCE, 0);     
//      SSMAIN_EXPLORERWINDOW_REBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT,REBARCLASSNAME,NULL, WS_CHILD|WS_BORDER|RBS_VARHEIGHT|TBS_HORZ|RBS_BANDBORDERS|CCS_NODIVIDER|CCS_NOPARENTALIGN,0,0,0,0,SSMAIN_EXPLORERWINDOW,NULL,0,0);     
        SSMAIN_NAVIGATIONTOOLBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,SSMAIN_REBARWINDOW, (HMENU)IDC_NAVIGATIONTOOLBAR, GetModuleHandle(NULL), NULL);
        SSMAIN_EXPLORERWINDOW_OVERVIEW=CreateWindowEx(0,"button",NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 4, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
        SSMAIN_EXPLORERWINDOW_DOCUMENT=CreateWindowEx(0,"button",NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 24, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
        SSMAIN_EXPLORERWINDOW_NEWFILE=CreateWindowEx(0,"button",NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 44, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
        SSMAIN_EXPLORERWINDOW_CLOSE=CreateWindowEx(0,"button",NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 62, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);

//      SSMAIN_PARENTCONTAINER=CreateWindow("SYSTABCONTROL32","", WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE,100,100,0,0,hwnd,(HMENU)ID_PARENTCONTAINER,SSMAIN_PARENTCONTAINER_HINSTANCE, NULL);                  
        SSMAIN_STATIC_RTF_CONTAINER=CreateWindowEx(WS_EX_TRANSPARENT|WS_EX_CLIENTEDGE,"static","",WS_CHILD,0,0,0,0,hwnd,(HMENU)IDC_STATIC_RTF_CONTAINER,0,0);
        SSMAIN_STATIC_RTFCONTROL_PARENT_HSCROLL=CreateWindow("SCROLLBAR","",WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE|SBS_BOTTOMALIGN,100,100,20,20,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_STATIC_RTFCONTROL_PARENT_HSCROLL,SSMAIN_PARENTCONTAINER_HINSTANCE,NULL);        
               
        SSMAIN_LISTBOXRTFCOUNT= CreateWindowEx(0,"LISTBOX",NULL,WS_CHILD|WS_CLIPSIBLINGS|ECO_AUTOVSCROLL|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_VISIBLE|WS_GROUP,0,0,0,0,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_LISTBOXRTFCOUNT,NULL,NULL);             
        
        SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","text",WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOHSCROLL|WS_VSCROLL|WS_HSCROLL|WS_GROUP,0,0,0,0,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_RTFCONTROL,SSMAIN_RTFCONTROL_HINSTANCE,0);

        SSMAIN_TOOLBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,hwnd, (HMENU)IDC_TOOLBAR, GetModuleHandle(NULL), NULL);
        SSMAIN_STATUSBAR=CreateWindow("MSCTLS_STATUSBAR32","", WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE,100,100,0,0,hwnd, NULL, 0, NULL);                          
       
        cout<<"CREATE 300:"<<SourceStudioConfiguration.error<<endl<<endl;   SendMessage(SSMAIN_STATUSBAR,SB_SETPARTS,(WPARAM)3,(LPARAM)&panes);
        SSMAIN_TOOLBARSYNTAX=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,SSMAIN_REBARWINDOW, (HMENU)IDC_TOOLBARSYNTAX, GetModuleHandle(NULL), NULL);
        SSMAIN_PWSBUTTON=CreateWindowEx(WS_EX_TRANSPARENT,"static",NULL,SS_BITMAP|TBSTYLE_TOOLTIPS|SS_NOTIFY|WS_CHILD|WS_VISIBLE,50,50,32,32,hwnd,(HMENU)IDC_PWSBUTTON,0,0);     
//... more code after this                                                                                                                                                            SSMAIN_TOOLTIP=CreateWindowEx(0,TOOLTIPS_CLASS,0,WS_POPUP|TTS_ALWAYSTIP,CW_USEDEFAULT,CW_USE    DEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hwnd,0,SSMAIN_HINSTANCE,0); 


Now for some reason after SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","... when I display cout<<"CREATE 300:"<<SourceStudioConfiguration.error<<endl<<endl; the text is all random text. Now if I used the same thing before SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","... it will display correctly like it should.

rest of this is below this post


My question is why is it doing that?

Also if I ignore SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","... as comment it will work like it should but then after some more lines on the cmd window it will display as random text again.

Is there something going on that I don't see? Like too much info going on where it start to mess with the error space and maybe setting something within it and it shouldn't?

Also as far as I can remember I didn't have this problem before I reinstalled my os.

Thanks and I'm really confused about this and if you need anymore info let me know and I'll post them

As for today before I go to work i'm going to go through all of this and see if I can find whats causing but this just leaves me as confused

Also in another forum someone mentioned that I was shouting so if I am i'm not trying to but if they are talking about SSMAIN_.. and etc I do that for a reason. Also someone gave me a tip about placing spaces after commas so i'm going to start doing that as well.
Last edited on
ok so I just tried something earlier today and I also added
1
2
3
4
5
6
7
8
9
10
User_Buffer=32767;
        OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken);
        GetUserProfileDirectory(hToken,InfoBuf,&User_Buffer);
        User_Path=InfoBuf;
//      cout<<InfoBuf<<endl<<endl;
        CharToStr<<InfoBuf<<"\\Source Studio\\preference.ini";
        preference=CharToStr.str();
        cout<<User_Path<<" : "<<preference<<endl<<endl;
//      SourceStudioConfiguration.file=preference;
        SourceStudioConfiguration.OpenFile(preference); 

under the WM_SIZE and now everytime I resize my window I no longer see something like "Sasfn%^&#^7ihmsdfn21*tt*&-546KGyt" and it ouputs C:\users\source studio\preferences.ini is currupt or not found!. Loading default configuration!" under the cmd window. Now if I remove that from the resize it will go back to random text.


Any ideas?
ok guys I believe the problems lies within the INI class.

if I change CharToStr2<<" is currupt or not found!. Loading default configuration!"; to // CharToStr2<<" is currupt or not found!. Loading default configuration!"; just leaving the file path instead it displays correctly through out the whole program as far as I can tell.

If I change it back it will go back to that garbled text. Also here the odd part as well. if I cout << SourceStudioConfiguration.error<<endl; after in the WM_CLASS after I assign the value then it still displays correctly but after say 100 lines within the WM_CREATE I add the same cout << SourceStudioConfiguration.error <<endl;it then turns into garbled text. Also no matter what under the WM_SIZE its always garbled unless I comment out CharToStr2<<" is currupt or not found!. Loading default configuration!"; or I re-set the SourceStudioConfiguration.file var.

So far i'm still looking and trying to figure this out.

Thanks for you help everyone, really appreciate it :D
ok everyone I believe I fixed the problem :D. I'll post the solution after I'm done with work today
ok guys here's the solution even though I don't know why if that makes any sense...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class INI_{    
        
    public:
    const char* error;
    stringstream CharToStr2;
    string errordesc;
    Layout layout;      
    Settings settings;  
    string file; 
 
    int OpenFile(string open_file){
    CharToStr2.str("");
    ifstream SSMAIN_FILE_SETTINGS; 
    CharToStr2<<open_file;
    cout<<"CharToStr: "<<CharToStr2<<endl;
    cout<<"CharToStr.str(): "<<CharToStr2.str()<<endl; 
    cout<<"CharToStr.str.c_str(): "<<CharToStr2.str().c_str()<<endl;
       
    SSMAIN_FILE_SETTINGS.open(CharToStr2.str().c_str());
        if(!SSMAIN_FILE_SETTINGS){
        CharToStr2<<" is currupt or not found!. Loading default configuration!";
        cout<<"STRING1:"<<CharToStr2<<endl<<endl;
        cout<<"STRING2:"<<CharToStr2.str()<<endl<<endl;
        cout<<"STRING3:"<<CharToStr2.str().c_str()<<endl<<endl;
        errordesc=CharToStr2.str();
        error=errordesc.c_str(); 
        cout<<"ERROR:"<<error<<endl;   
        }
    cout <<"CLASS INI_: "<<SSMAIN_FILE_SETTINGS<<" : "<<file<<endl<<endl;
}
};


Noticed that I added a variable string errordesc and assigned the source stream to that, then assigned errordesc to error
Topic archived. No new replies allowed.