Subject: Re: Windows application
From: [email-masked] (Dennis Newbold)

5 Sep 1998 06:56:19 -0700
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: LO <[email-masked]>
Cc: [email-masked]

Hi LO,

     The compiler doesn't like the following line:

           WndClass.lpfnWndProc = WndProc;

     This is because, if you look through the proper header files, WORD is
     defined as an unsigned short int, whereas WndClass.lpfnWndProc is
     defined as a pointer to a function which returns a long int and expects
     the following as parameters:

        1st parameter:  void * -- that hWnd
        2nd parameter: unsigned int -- that's iMessage
        3rd parameter: unsigned int -- that's wParam
        4th parameter: long int --         that's lParam

In other words the function prototypes don't match because the parameters
don't
match.  The compiler wants you to specify the name of a function whose 2nd and

3rd parameters are unsigned ints, and you are specifying the name of a
function
whose 2nd and 3rd parameters are short unsigned ints, which is (at least to
the
mind of the fussy compiler) not the same thing.

     You can probably make the compiler happy by doing some casting.  What I'm

not sure about here, and I hope someone else on the list can help out is:

   I think casting is begging the larger issue.  You may need to fix the
definition
   of WndProc to expect the same thing as lpfnWndProc is pointing to.
   Specifically, I think that the WIN32 API defines iMessage and wParam to
   be 32-bit values rather than 16-bit values.  This was one of the changes
made
   in going from WINDOWS 3.1 to WINDOWS 95.  And since you took the
   example code from a book called "Windows 3.1 Programmers Reference",
   you may be trying to compile WIN 3.1 code against WIN95 header files.
   Check out your windows.h header file.  Also, try to find a book called
   something like WIN32 Programmers Reference, and use it for future
   programming efforts to avoid other subtle gotchas like this one.

   I may be wrong here, because I'm working with some rather dusty memories,
   as I mostly do embedded stuff, and haven't looked at the WINxx API docu-
   mentation for some time.  Can anyone else on the list confirm / negate
   what I'm saying here.

    Thanks a lot, and have a nice day.

LO wrote:

> Hi,
>
> I saved the following code in a file called w.c.The code is supposed to
> create a Microsoft Windows applicaton.
> I am using Windows 95 and cygwinb19 on a Intel Pentium PC.
> //------------start-----------------//
> #include <windows.h>
> #include <stdlib.h>
> #include <string.h>
>
> long FAR PASCAL WndProc (HWND hWnd, WORD iMessage, WORD wParam, LONG
> lParam);
> int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR
> lpszCmdParam, int nCmdShow)
>
> {
> HWND hWnd;
> MSG Message;
> WNDCLASS WndClass;
>
> if (!hPrevInstance)
> {
> WndClass.cbClsExtra = 0;
> WndClass.cbWndExtra = 0;
> WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
> WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
> WndClass.hIcon = LoadIcon (NULL,  "END");
> WndClass.hInstance = hInstance;
> WndClass.lpfnWndProc = WndProc;
> WndClass.lpszClassName = "w";
> WndClass.lpszMenuName = "MENU";
> WndClass.style = CS_HREDRAW | CS_VREDRAW;
>
> RegisterClass (&WndClass);
> }
>
> hWnd = CreateWindow ("w",
> "Fundamental Window",
> WS_OVERLAPPEDWINDOW,
> CW_USEDEFAULT,
> 0,
> CW_USEDEFAULT,
> 0,
> NULL,
> NULL,
> hInstance,
> NULL);
>
> ShowWindow (hWnd, nCmdShow);
> while (GetMessage (&Message, 0, 0, 0))
> {
> TranslateMessage(&Message);
> DispatchMessage(&Message);
> }
> return Message.wParam;
> }
>
> long FAR PASCAL WndProc (HWND hWnd, WORD iMessage, WORD wParam, LONG
> lParam)
> {
> switch(iMessage)
> {
> case WM_DESTROY:
> PostQuitMessage(0);
> return 0;
> default:
> return(DefWindowProc(hWnd, iMessage, wParam, lParam));
> }
> }
> //-----------------end-------------------------------------
> w.c is in the dierctory C:\Cygnus\B19\
> I then type GCC W.C at the prompt.
> Nothing appears on screen for about 5 seconds.
> Then the following text appears. What I typed is in bold text.
>
> BASH.EXE-2.01$ GCC W.C
> W.C: In function `int WinMain(void *, void *, char *, int)':
> W.C:22: assignment to `long int (*)(void *, unsigned int, unsigned int,
> long int
> )' from `long int (*)(void *, short unsigned int, short unsigned int,
> long int)'
>
> BASH.EXE-2.01$
>
> Does anyone know whats wrong? The program is from the book "Windows 3.1
> Programmers Reference" and is published by Que.
>
> Liam O'Keeffe.
> Web site: http://homepages.iol.ie/~lo7
>
> -
> For help on using this list (especially unsubscribing), send a message to
> "[email-masked]" with one line of text: "help".

--
|----------------------------------------|
|                                        |
|  The way to be happy is to be good.    |
|                                        |
|----------------------------------------|

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".