NO

Author Topic: static void error  (Read 3450 times)

FromB2C

  • Guest
static void error
« on: September 04, 2016, 12:01:04 PM »
Hi, I did a lot of programming in Basic and now want to learn C. I played a bit with the MDI-example. I added a statusbar by adding three lines in the WinMain function:

Code: [Select]
HWND hwndStatus;
int IDC_STATUSBAR = 10001;
hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, "start text", SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE,
               //0, 0, 0, 0, hwnd, (HMENU)IDC_STATUSBAR, ghInstance, 0);

This works. Now I would like to move these lines to a new file. So I added a file 'statusbar.c' and moved the three lines there, as part of a new function 'static void CreateStatusBar'.

I add this one as prototype as 'static void CreateStatusBar;'

Now when I compile, I get an error:
error #2149: Undefined size for 'CreateStatusBar' with type 'void'.
Where do I need to add a size to this prototype? And what size?

Any help would be appreciated.
W-EU

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: static void error
« Reply #1 on: September 05, 2016, 06:34:36 PM »
It would help if you would post your not working code (both the new .c file you created as well as the one that contains the prototype that you mentioned) instead of posting of three lines of code that are working and not related to the error you get.

Best WAG is that your function declaration in the new .c file and that prototype don't match or that the later isn't in the right place...

Ralf

FromB2C

  • Guest
Re: static void error
« Reply #2 on: September 05, 2016, 07:29:23 PM »
The new .c file contains this code:
Code: [Select]
static void CreateStatusBar
{
  HWND hwndStatus;
  int IDC_STATUSBAR = 10001;
  hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, "start text", SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE,
               0, 0, 0, 0, hwnd, (HMENU)IDC_STATUSBAR, ghInstance, 0);
}

In the main file, under the existing prototypes, I added the line:
Code: [Select]
static void CreateStatusBar;
It is this last line that is causing the error.

I am aware that I can not use the handle of the statusbar elsewhere if I define it this way, but that's not the issue here.

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: static void error
« Reply #3 on: September 05, 2016, 07:41:37 PM »
Code: [Select]
HWND CreateStatusBar(HWND hwnd)
{
  HWND hwndStatus;
  int IDC_STATUSBAR = 10001;
  hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, "start text", SBARS_SIZEGRIP|WS_CHILD|WS_VISIBLE,
               0, 0, 0, 0, hwnd, (HMENU)IDC_STATUSBAR, ghInstance, 0);
  return hwndStatus;
}
You may need that hwnd later.
Code: [Select]
HWND CreateStatusBar(HWND hwnd);
« Last Edit: September 05, 2016, 07:44:54 PM by TimoVJL »
May the source be with you

FromB2C

  • Guest
Re: static void error
« Reply #4 on: September 05, 2016, 09:34:12 PM »
Thanks. But what and where should then be the prototype? If I include it in main.c, I get an error #2150: Undefined static function 'CreateStatusBar'. It does not seem to recognize the function in the other file...

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: static void error
« Reply #5 on: September 06, 2016, 01:15:38 PM »
Timo hasn't used the 'static' qualifier.
The prototype, as Timo already said, must be:
Code: [Select]
HWND CreateStatusBar(HWND hwnd);If you define a function as 'static' the compiler expect to find it in the same module (file) from where it is called.
C is very different from Basic, I suggest you to read some tutorial on C programming.
« Last Edit: September 06, 2016, 03:03:36 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide