Dev C++ won't compile header files

I'm making a basic win api application and it was going fine until I made changes to the input function in the header file.

This is the function

1
2
3
4
5
6
7
8
9
void gettxt(){
     int len = GetWindowTextLength(GetDlgItem(hEnterText, IDC_TEXT));
     if(len > 0){
            junk = (char*)GlobalAlloc(GPTR, len + 1);
            GetDlgItemText(hwnd, IDC_TEXT, junk, len + 1);
            MessageBox(hwnd, junk, "test",0);
            GlobalFree((HANDLE)junk);
            }
}


It reads the text in an edit control box. This should work fine; however, when I compiled it to the main.cpp file; the program ran without error, but it didn't read my changes.

My original function looked like this:
1
2
3
4
5
6
7
8
void gettxt(){
     int len = GetWindowTextLength(GetDlgItem(hEnterText, IDC_TEXT));
     if(len > 0){
            junk = (char*)GlobalAlloc(GPTR, len + 1);
            GetDlgItemText(hwnd, IDC_TEXT, junk, len + 1);
            GlobalFree((HANDLE)junk);
            }
}


Without the MessageBox.

I have already made sure that the header file is included in linking, compiling and what not. I rebuilt the code, overwrote the build command and the application still compiles without displaying the Messagebox.

This is fairly annoying; so can anyone try to find a solution to my problem?

The compiler I am using is Dev C++ 4.9.9.2 on Windows 7
I see you allocating the space on Line 4, reading the data on Line 5 and then immediatly freeing the memory on Line 6. My guess is that if this really isn't being compiled it's because it was optimized out by the compiler. By default Dev C++ uses Mingw which acts a lot like GCC for Windows. Here is a link to the compiler options I'm pretty sure one of them turns of compiler optimization: http://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html#C_002b_002b-Dialect-Options
Topic archived. No new replies allowed.