VC++ Win32 SDK Issues

This is a discussion on VC++ Win32 SDK Issues within the C++ Programming forums, part of the General Programming Boards category; I purchased Role-Playing Game Programming with DirectX and I thought this would be a good time for me to start ...

  1. #1
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

    VC++ Win32 SDK Issues

    I purchased Role-Playing Game Programming with DirectX and I thought this would be a good time for me to start using Visual C++ since almost all of what I have read says it is the best when having to deal with DirectX.

    I am 70% sure I installed the SDK right, but I am getting errors that make it look like it is not installed properly. I can build a basic program with just a WinMain and return 0; but when I started to do more I started to get a lot of errors:

    PHP Code:
    ------ Build startedProjectWinTestConfigurationDebug Win32 ------
    Linking...
    main.obj error LNK2019unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
    main.obj error LNK2019unresolved external symbol __imp__DefWindowProcA@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
    main.obj error LNK2019unresolved external symbol __imp__UnregisterClassA@8 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__DispatchMessageA@4 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__PeekMessageA@20 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__UpdateWindow@4 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__ShowWindow@8 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__CreateWindowExA@48 referenced in function _WinMain@16
    main
    .obj error LNK2019unresolved external symbol __imp__RegisterClassExA@4 referenced in function _WinMain@16 
    My code is:

    Code:
    #include <windows.h>
    
    int WINAPI WinMain(
    	HINSTANCE hInstance,
    	HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine,
    	int nShowCmd);
    
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    
    int WINAPI WinMain(
    	HINSTANCE hInstance,
    	HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine,
    	int nShowCmd)
    {
    	WNDCLASSEX wcex = {sizeof(WNDCLASSEX), CS_CLASSDC, 
    					   WindowProc, 0L, 0L, hInstance, NULL,
    					   NULL, NULL, NULL, "GameClass", NULL};
    	
    	if(!RegisterClassEx(&wcex))
    		return false;
    
    	HWND hWnd;
    	hWnd = CreateWindow("GameClass", "Knights of the Wraith",
    		   WS_OVERLAPPEDWINDOW, 0, 0, 400, 400, NULL, NULL, 
    		   hInstance, NULL);
    
    	if(hWnd == NULL)
    		return false;
    
    	ShowWindow(hWnd, SW_SHOWNORMAL);
    	UpdateWindow(hWnd);
    
    	MSG Msg;
    	
    	ZeroMemory(&Msg, sizeof(MSG));
    
    	while(Msg.message != WM_QUIT) {
    		if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
    			TranslateMessage(&Msg);
    			DispatchMessage(&Msg);
    		} else {
    		}
    	}
    
    	UnregisterClass("GameClass", hInstance);
    
    	return 0;
    }
    
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uMsg){
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    
    		default: return DefWindowProc(hWnd, uMsg, wParam, lParam);
    	}
    	return 0;
    }
    I have looked up the SDK and checked everything and it all looks like the code is valid and the SDK is set up right.

    ~Wraith
    Last edited by Wraithan; 02-12-2006 at 09:51 AM.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Your compiler does not seem to be recognizing the <windows.h> library.. Be sure you compile your windows api program as a, "windows project" (as opposed to DOS Console)
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    How would I change my project after already making it, in dev-cpp it was as simple as changing an option in the linker settings, but I don't see an option in the configuration stuff for VC++.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's a Win32 Application all right, not a console application. (You'd get linker errors complaining about not finding _main.)

    The issue here is that you don't link to user32.lib. You can add it in the linker options, section Input. (Project->Settings->Linker Options->Input) Be sure to set it in all profiles.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    63
    I don't think you need to prototype WINAPI WinMain() because like main() it is self-prototyping.

    If you add #pragma comment(linker,"/subsystem:windows")
    Under your includes for your header files, it will tell the compiler at compile time you wish to create a windows application not a console application, so it saves you messing about with the IDE, that is for MSVC++ by the way.

    Also adding #pragma comment(lib,"user32.lib")
    under your includes will also tell the compile to add it so you don't need to mess with the IDE settings.
    Last edited by John_; 02-12-2006 at 10:12 AM.

  6. #6
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Thank you much CornedBee.

    John_ The book I am using said to do that, I thought it was odd, but I haven't ever use win32 API before so I thought it might be normal. I commented it out and it worked fine so I think I will just omit it in the future, thanks for the tips.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Wraithan
    The book I am using said to do that,
    My guess is the author of the book simply prototypes every function in a file just to give an overview of the contents.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    That could be it, I went back to the section that said to do that, and it was lumped in with how great prototyping is because of default values. This book is ment for a C programmer who is starting into C++, but it seems to be working fine for me, who has never coded any C, just C++

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  2. Win32 API Speed Issues
    By samGwilliam in forum Windows Programming
    Replies: 7
    Last Post: 12-07-2005, 07:32 AM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 04:26 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. TCP/IP and Win32 SDK Books
    By punkrockguy318 in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-22-2004, 09:45 PM

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