Error while windows programming in C

This is a discussion on Error while windows programming in C within the C Programming forums, part of the General Programming Boards category; hello, I am reading a book "Let Us C" by Yashwant Kanetkar. Book For learning C programming. In that book ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    19

    Error while windows programming in C

    hello,
    I am reading a book "Let Us C" by Yashwant Kanetkar.
    Book For learning C programming.
    In that book towards the end, After done with C Programming, It teaches a lil bit of windows and linux programming.

    In windows programming , it started with this code and advised to compile it and see the output before starting to learn about it . (in visual c++ 6.0 standard edition)
    The code is :

    Code:
    #include <windows.h>
    
    
    int_stdcall WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdline, int nCmdShow)
    {
    MessageBox (0,"Hello!","Title",0);
    return 0;
    }
    But it gives 3 errors , VC++ doesnt point out those errors , can you help me with it?
    Also, suggest me something else better than vc++ for win32 aplication building.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    > But it gives 3 errors , VC++ doesnt point out those errors , can you help me with it?
    Try scrolling up the build log window using the scroll bars.

    "There are 3 errors" is about as useful as the typical newbie post of "can anyone help" or "there are errors", without actually saying what the problem is.

    > int_stdcall WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdline, int nCmdShow)
    Did you copy this correctly?
    Try
    int stdcall

    Or maybe even just remove the stdcall altogether.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    19
    My apologies,
    I didnt knew there was a scroll bar in there so didnt try to .
    The error is :
    Code:
    Sample.c
    c:\program files\microsoft visual studio\myprojects\sample\sample.c(4) : error C2061: syntax error : identifier 'WinMain'
    c:\program files\microsoft visual studio\myprojects\sample\sample.c(4) : error C2059: syntax error : ';'
    c:\program files\microsoft visual studio\myprojects\sample\sample.c(4) : error C2059: syntax error : 'type'
    Error executing cl.exe.
    
    
    Sample.exe - 3 error(s), 0 warning(s)
    Still gives the same error, With int stdcall.

    The author have mentioned that the stdcall is there besides the int , to notify the compiler the way ( right to left , or left to right) the parameters are to be passes to the stack and also who will clear the stack , the calling function or the called function. If i wud remove stdcall then will the compiler get confused??

    Still, tried without stdcall besides the int ,
    The following error and a warning occurs,
    Code:
    Sample.c
    C:\Program Files\Microsoft Visual Studio\MyProjects\Sample\Sample.c(5) : warning C4007: 'WinMain' : must be '__stdcall'
    Linking...
    LINK : fatal error LNK1104: cannot open file "Debug/Sample.exe"
    Error executing link.exe.

    It says winmain must be _stdcall

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to go about programming windows.
    By cruiser in forum C++ Programming
    Replies: 6
    Last Post: 09-02-2011, 06:04 AM
  2. Differences between Windows XP and Windows Vista programming
    By nathan3011 in forum Windows Programming
    Replies: 3
    Last Post: 01-15-2009, 10:05 AM
  3. Programming Windows
    By herWter in forum Windows Programming
    Replies: 3
    Last Post: 07-03-2008, 10:57 AM
  4. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 03:16 PM
  5. windows programming
    By Klinerr1 in forum Windows Programming
    Replies: 2
    Last Post: 06-28-2002, 02:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21