Archived

This topic is now archived and is closed to further replies.

Problems with VC++7/ .Net

This topic is 5584 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all -- Ok, I'm trying to get VC++ 7 to compile this simple (?) Windows program:
      
///////////////////////////////////////////////////////////////////////////////

//winmain.cpp                                                                //

//                                                                           //

//Hello, World!                                                              //

//                                                                           //

//Copyright (C) 2002, John de Michele                                        //

//Based on hellowin.c in Petzold, 5E                                         //

///////////////////////////////////////////////////////////////////////////////


//-------------------------------Includes------------------------------------//


#include <windows.h>

//------------------------------Prototypes-----------------------------------//


LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);

//-------------------------------Functions-----------------------------------//


///////////////////////////////////////////////////////////////////////////////

//WinMain()                                                                  //

//                                                                           //

//Main Windows function.                                                     //

//                                                                           //

///////////////////////////////////////////////////////////////////////////////

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd) {

	static TCHAR szAppName[] = TEXT("Hello, World!");
	HWND hwnd;
	MSG msg;
	WNDCLASS wndclass;

	wndclass.style =         CS_HREDRAW | CS_VREDRAW
	wndclass.lpfnWndProc =   WndProc;
	wndclass.cbClsExtra =    0;
	wndclass.cbWndExtra =    0;
	wndclass.hInstance =     hInstance;
	wndclass.hIcon =         LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor =       LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName =  NULL;
	wndclass.lpszClassName = szAppName;

	if (!RegisterClass(&wndclass)) {

		MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR);

		return (0);

	}

	hwnd = CreateWindow (szAppName,						//window class name

						 TEXT("Hello World!"),			//window caption

						 WS_OVERLAPPEDWINDOW,			//window style

						 CW_USEDEFAULT,					//initial x position

						 CW_USEDEFAULT,					//initial y position

						 CW_USEDEFAULT,					//initial x size

						 CW_USEDEFAULT,					//initial y size

						 NULL,							//parent window handle

						 NULL,							//window menu handle

						 hInstance,						//program instance handle

						 NULL);							//creation parameters


	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	while (GetMessage(&msg, NULL, 0, 0)) {

		TranslateMessage(&msg);
		DispatchMessage(&msg);

	}

	return msg.wParam;

}

///////////////////////////////////////////////////////////////////////////////

//WinProc()                                                                  //

//                                                                           //

//Windows message processing.                                                //

//                                                                           //

///////////////////////////////////////////////////////////////////////////////

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

	HDC hdc;
	PAINTSTRUCT ps;
	RECT rect;

	switch (message) {

		case WM_CREATE: {

			PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);

			return (0);

			break;

		}

		case WM_PAINT: {

			hdc = BeginPaint(hwnd, &ps);

			GetClientRect(hwnd, &rect);

			DrawText(hdc, TEXT("Hello, World!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);

			EndPaint(hwnd, &ps);

			return (0);

			break;

		}

		case WM_DESTROY: {

			PostQuitMessage(0);

			return (0);

			break;

		
		}

		default: {

			return DefWindowProc(hwnd, message, wParam, lParam);

			break;

		}

	}; //switch


}

///////////////////////////////////////////////////////////////////////////////

//End winmain.cpp                                                            //

///////////////////////////////////////////////////////////////////////////////

      
VC++ 7 builds this without any errors, but when I try to link it, I get this linker error: error LNK2001: unresolved external symbol _WinMainCRTStartup Here is my linker command line: /OUT:"Debug/Wintest.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"Debug/Wintest.pdb" /SUBSYSTEM:WINDOWS /MACHINE:IX86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib winmm.lib Any ideas? John. [edited by - JohnAD on August 28, 2002 11:15:07 PM] [edited by - JohnAD on August 28, 2002 11:15:25 PM]

Share this post


Link to post
Share on other sites
Well, at this point it seems like the only option is to reinstall. I''m going to have to do that with my VS 6 as well, which started this problem in the first place.

John.

Share this post


Link to post
Share on other sites
How did you create this project in the first place? Theres a wizard that sets up a boilerplate Win32 app for you.


"PL/I and Ada started out with all the bloat, were very daunting languages, and got bad reputations (deservedly). C++ has shown that if you slowly bloat up a language over a period of years, people don''t seem to mind as much."

James Hague

Share this post


Link to post
Share on other sites
Arild Fines:

Yes, I know. I created a blank Win32 Windows app, and then copied the winmain.cpp text from the file that I had it in. I guess I can try what is automatically generated when I get home from work, but at this point I''m very frustrated.

John.

Share this post


Link to post
Share on other sites
I can get Visual C++ 6.0 to give me that error if I go into the Project Settings, go to the Link tab, select the Input category and check Ignore all default libraries. Make sure that setting is not checked.
If that doesn''t help, you could try explicitly linking with libc.lib.

Share this post


Link to post
Share on other sites