tags:

views:

23

answers:

1

I'm working through theForger's win32 tutorial, on two IDEs: Dev C++ and Visual Studio 2008. I try to duplicate results in both.

For this page of the tutorial, I can't seem to compile in Dev C++ (Visual Studio works fine). It's a modal dialog box. The code in question is in WndProc:

case ID_HELP_ABOUT:

  int ret = DialogBox(GetModuleHandle(NULL),
    MAKEINTRESOURCE(IDD_ABOUT),hwnd,AboutDlgProc);   //ERROR OCCURS HERE in Dev C++

  if(ret==IDOK) { MessageBox(NULL,"Dialog exited with OK","Notice",0); }
  else { MessageBox(NULL,"Dialog exited with EXIT","Notice",0); }

break;

The error(s) it throws are:

Simple3\main.c In function `WndProc': 
Simple3\main.c syntax error before "int" 
Simple3\main.c `ret' undeclared (first use in this function) 

If I define int ret; before this point, it compiles, but a command window opens along with the regular app.

I assume I'm missing a header. The headers I'm using are windows.h and afxres.h. Could anyone help me out? Thanks in advance.

PS - real easy question while I'm at it - what's the difference between declaring headers in angle brackets or quotes? E.g. <windows.h> or "windows.h" ?

A: 

Some compilers expect curly braces to be added between Case statement and break. Try using it.

I think it should work that way.

Besides regarding <> and "" for declaring headers, angular brackets indicate that the file will be searched in the default include directories mentioned with IDE. Whereas the "" are used when you want the file to be searched in the local project folder as well along with the include folder.

krissam
This solution will work, but not for the reason you think. It works because he declares a variable within the case block. And if this case block is skipped, the variable will not be created, but it should still exist, because it's in the same scope. That's a problem. Putting curly braces around it limits the scope, that's why it works.
PigBen
Ahh, so it's a basic C++ problem, not a compiler problem. Will check and see (24 hrs...). Thanks!
Steve