WinAPI linking error

This is a discussion on WinAPI linking error within the C Programming forums, part of the General Programming Boards category; Hi! I'm learning to program the WinAPI and I was getting linking errors and had to manually configure MSVC++ ver ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    207

    WinAPI linking error

    Hi!

    I'm learning to program the WinAPI and I was getting linking errors and had to manually configure MSVC++ ver 6.0 in order for my program to link correctly. A friend of mine gave me some code that makes the program automatically link correctly without any manual configuration. I'm using Windows XP and don't know how portable this is. I just thought I'd share the code:

    Code:
    #include <stdio.h>
    #include <windows.h>
    
    //WinAPI linking code
    #pragma comment (linker, "/ENTRY:WinMainCRTStartup")
    #ifdef _DEBUG
    #pragma comment (linker, "/subsystem:windows")
    #endif
    mw
    Blucast Corporation

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I was getting linking errors and had to manually configure MSVC++ ver 6.0 in order for my program to link correctly.
    Your linker errors probably came from the fact that when you created a new project, you selected "new console application" instead of "new win32 application". That is why you had to manually configure your project settings.

    Secondly, I dont think the code your friend gave you is correct. The /subsystem:windows linker command should be given in both debug and release configurations -- not just debug as your code implies (Unless you might want a console window in release builds for some reason).

    Also keep in mind none of these settings are mandatory. You can always have a win32 application which looks like the following:

    Code:
    #include <windows.h>
    
    #pragma comment (linker, "/ENTRY:mainCRTStartup")
    #pragma comment (linker, "/subsystem:windows")
    
    int main(void)
    {
    	HINSTANCE	hInst;
    	hInst = GetModuleHandle(NULL);
    	MessageBox(NULL,_T("Hello World"),_T("HW"),MB_OK);
    	return 0;
    }
    And following the same principals, you can have a console application which looks like:
    Code:
    #pragma comment (linker, "/ENTRY:WinMainCRTStartup")
    #pragma comment (linker, "/subsystem:console")
    
    
    int PASCAL WinMain(HINSTANCE hi, HINSTANCE hp, LPSTR lpcmd, int nShow)
    {
    	printf("Hello World!\n");
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    207
    Do you know any good WinAPI forums?

    mw
    Blucast Corporation

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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