Thread: Microsoft Visual C++ 6.0 ** Am I missing something?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    46

    Microsoft Visual C++ 6.0 ** Am I missing something?

    People have told me that in the workplace visual C++ is the standard compiler that you work with.... so I bought visual studio and have been using it rather then gcc/bloodshed. I'm trying to learn windows based programming but keep on getting errors on code that will compile in bloodshed. Can someone who used visual C++ tell me what I have to do to this code and why simple **** won't compile in visual... I gota be missing something.

    #include <stdio.h>
    #include <windows.h>

    main()
    {
    MessageBox (NULL, "blaat" , "fux0r owned j00", 0 | MB_ICONEXCLAMATION);
    system("PAUSE");
    return 0;
    }

  2. #2

    Talking msgbox

    It might have something to do with Microsoft trying to take over the world!!

  3. #3
    this is code for a console application.
    if this is the error you get:unresolved external symbol _WinMain@16
    this means you are in a win32 application

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    5

    Re: Microsoft Visual C++ 6.0 ** Am I missing something?

    I'm don't know why bloodshed allows the code to compile . . . I've never used bloodshed, so I comment on it's ability. However, in Visual C++ 6, your code will compile if you use the Win32 Application entrance (instead of the Win32 Console Application entrance):

    I called the following "testmsg.c":

    //////////////////////////////////////////////////////////////////////////
    #include <stdio.h>
    #include <windows.h>

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    MessageBox (NULL, "blaat" , "fux0r owned j00", 0 | MB_ICONEXCLAMATION);
    system("PAUSE");
    return 0;
    }
    //////////////////////////////////////////////////////////////////////////

    I'm not familiar with system("PAUSE") in Windows, so I don't know if it's necessary. If you can do without it, then you can probably lose stdio.h as well. Also, you might want to use windows.h's TEXT() macro around the strings, if you plan on using UNICODE.

    If you're not used to seeing all of the above Windows typedefs, don't worry . . . they're really, really easy after you get Petzold's Programming Windows (off of e-bay ).

    Hope This Helps,
    Joshua Burkholder

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    12

    Lightbulb Dev-C++

    try to create a "WinMain() Projekt" and then compile...

    Not a "windows application"...

    ...I think that is for win16 app's, but, i'm still new to programming, so what do I know *huhu*
    I'm a newbie, so don't take my words for facks!
    btw, I'm useing Dev-4

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Can someone who used visual C++ tell me what I have to do to
    >this code and why simple **** won't compile in visual...
    What exactly is it doing? Because your code works just fine for me. Please specify any errors.

    -Prelude
    My best code is written with the delete key.

  7. #7
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    Reason it will compile in bloodshed is because the handlers are neglected and it is launched as a console application
    when the program is written in MSVC++ you need to handle the handlers.
    like...
    Code:
    // wintest.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    #include "resource.h"
    
    #define MAX_LOADSTRING 100
    
    // Global Variables:
    HINSTANCE hInst;								// current instance
    TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text
    
    // Foward declarations of functions included in this code module:
    ATOM				MyRegisterClass(HINSTANCE hInstance);
    BOOL				InitInstance(HINSTANCE, int);
    LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	// TODO: Place code here.
    	MSG msg;
    	HACCEL hAccelTable;
    
    	// Initialize global strings
    	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    	LoadString(hInstance, IDC_WINTEST, szWindowClass, MAX_LOADSTRING);
    	MyRegisterClass(hInstance);
    
    	// Perform application initialization:
    	if (!InitInstance (hInstance, nCmdShow)) 
    	{
    		return FALSE;
    	}
    
    	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINTEST);
    
    	// Main message loop:
    	while (GetMessage(&msg, NULL, 0, 0)) 
    	{
    		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	return msg.wParam;
    }
    
    
    
    //
    //  FUNCTION: MyRegisterClass()
    //
    //  PURPOSE: Registers the window class.
    //
    //  COMMENTS:
    //
    //    This function and its usage is only necessary if you want this code
    //    to be compatible with Win32 systems prior to the 'RegisterClassEx'
    //    function that was added to Windows 95. It is important to call this function
    //    so that the application will get 'well formed' small icons associated
    //    with it.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	WNDCLASSEX wcex;
    
    	wcex.cbSize = sizeof(WNDCLASSEX); 
    
    	wcex.style			= CS_HREDRAW | CS_VREDRAW;
    	wcex.lpfnWndProc	= (WNDPROC)WndProc;
    	wcex.cbClsExtra		= 0;
    	wcex.cbWndExtra		= 0;
    	wcex.hInstance		= hInstance;
    	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_WINTEST);
    	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
    	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
    	wcex.lpszMenuName	= (LPCSTR)IDC_WINTEST;
    	wcex.lpszClassName	= szWindowClass;
    	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
    
    	return RegisterClassEx(&wcex);
    }
    
    //
    //   FUNCTION: InitInstance(HANDLE, int)
    //
    //   PURPOSE: Saves instance handle and creates main window
    //
    //   COMMENTS:
    //
    //        In this function, we save the instance handle in a global variable and
    //        create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
    
       hInst = hInstance; // Store instance handle in our global variable
    
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       if (!hWnd)
       {
          return FALSE;
       }
    
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
       return TRUE;
    }
    
    //
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  PURPOSE:  Processes messages for the main window.
    //
    //  WM_COMMAND	- process the application menu
    //  WM_PAINT	- Paint the main window
    //  WM_DESTROY	- post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	int wmId, wmEvent;
    	PAINTSTRUCT ps;
    	HDC hdc;
    	TCHAR szHello[MAX_LOADSTRING];
    	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
    
    	switch (message) 
    	{
    		case WM_COMMAND:
    			wmId    = LOWORD(wParam); 
    			wmEvent = HIWORD(wParam); 
    			// Parse the menu selections:
    			switch (wmId)
    			{
    				case IDM_ABOUT:
    				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
    				   break;
    				case IDM_EXIT:
    				   DestroyWindow(hWnd);
    				   break;
    				default:
    				   return DefWindowProc(hWnd, message, wParam, lParam);
    			}
    			break;
    		case WM_PAINT:
    			hdc = BeginPaint(hWnd, &ps);
    			// TODO: Add any drawing code here...
    			RECT rt;
    			GetClientRect(hWnd, &rt);
    			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
    			EndPaint(hWnd, &ps);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }
    
    // Mesage handler for about box.
    LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch (message)
    	{
    		case WM_INITDIALOG:
    				return TRUE;
    
    		case WM_COMMAND:
    			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
    			{
    				EndDialog(hDlg, LOWORD(wParam));
    				return TRUE;
    			}
    			break;
    	}
        return FALSE;
    }
    all this for Hello, World! (yet people still ask me why I don't use Windows as much as Linux)
    well actually there are more things with this app like menus and stuff but you need to handle the windows calls.
    this is the begining of the handlers WinMain:
    Code:
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    The above is incorrect.....that is for a fullblown win32 window app......and it can even then be implemented simpler than that example....

    You can run the following code as a console app under VC++6

    Code:
    #include <stdlib.h>
    #include <windows.h>
    
    int main()
    {
    
    MessageBox (NULL, "blaat" , "fux0r owned j00", 0 | MB_ICONEXCLAMATION);
    system("PAUSE");
    return 0;
    }
    Or without the console (as a win32 app)....

    Code:
    
    #include <windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    MessageBox (NULL, "blaat" , "fux0r owned j00", 0 | MB_ICONEXCLAMATION);
    
    return 0;
    }
    Note that the system function is useless as you are not using a console......it will simply raise a console and sit there so there's no point
    Last edited by Fordy; 05-15-2002 at 03:03 AM.

  9. #9
    sodsm live
    Guest
    you also need the stdlib.h header if you want to use system() in vc++

  10. #10
    sodsm live
    Guest
    Then again I shouldn't post at 4:00 in the morning since I'm not paying attention to what I'm reading, disregard that above post.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  2. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  3. Apps that act "differently" in XP SP2
    By Stan100 in forum Tech Board
    Replies: 6
    Last Post: 08-16-2004, 10:38 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. header file bringing errors?
    By bluehead in forum Windows Programming
    Replies: 4
    Last Post: 08-19-2003, 12:51 PM