Sign in to follow this  

Having trouble with code

This topic is 3729 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

#include<windows.h>
LRESULT WINAPI WndProc(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam);
void RegisterWindowClass(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
WPARAM StartMessageLoop();

HWND g_hWnd;

//WinMain()

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT)
{
    RegisterWindowClass(hInstance);
    CreateAppWindow(hInstance);
    ShowWindow(g_hWnd, SW_SHOWDEFAULT);
    UpdateWindow(g_hWnd);
    INT result = StartMessageLoop();
    return result;
    
}

LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
        switch(msg)
        {
                   case WM_CREATE:
                        return 0;
                        
                   case WM_DESTROY:
                        PostQuitMessage( 0 );
                        return 0;
                        
                   case WM_PAINT:
                        ValidateRect(g_hWnd, NULL);
                        return 0;
        }
        return DefWindowProc(hWnd, msg, wParam, lParam);
}

void RegisterWindowClass(HINSTANCE hInstance)
{
     WNDCLASSEX wc;
     wc.cbSize = sizeof(WNDCLASSEX);
     wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
     wc.lpfnWndProc = WndProc;
     wc.cbClsExtra = 0;
     wc.cbWndExtra = 0;
     wc.hInstance = hInstance;
     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
     wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
     wc.lpszMenuName = NULL;
     wc.lpszClassName = "winAPP";
     wc.hIconSm = NULL;
     
     RegisterClassEx(&wc);
}
                             
void CreateAppWQindow(HINSTANCE hInstance)
{
     g_hWnd = CreateWindowEx(
     NULL, 
     "WinApp",
     "Basic Windows Application",
     WS_OVERLAPPEDWINDOW,
     100,
     100,
     648,
     514,
     GetDesktopWindow(),
     NULL,
     hInstance,
     NULL);
}

WPARAM StartMessageLoop()
{
       MSG msg;
       while(1)
       {
               if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
               {
                  if (msg.message == WM_QUIT)
                  break;
                  TranslateMessage(&msg);
                  DispatchMessage(&msg);
               }
               else
               {
               void;
               }
       }
       return msg.wParam;
}    

  
/

I am having so many problems trying to get this to build an .exe I am getting a ton of error. 
the errors are as following

1>------ Build started: Project: fuckenwork, Configuration: Debug Win32 ------
1>Linking...
1>main.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__ValidateRect@8 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__RegisterClassExA@4 referenced in function "void __cdecl RegisterWindowClass(struct HINSTANCE__ *)" (?RegisterWindowClass@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__GetStockObject@4 referenced in function "void __cdecl RegisterWindowClass(struct HINSTANCE__ *)" (?RegisterWindowClass@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__LoadCursorA@8 referenced in function "void __cdecl RegisterWindowClass(struct HINSTANCE__ *)" (?RegisterWindowClass@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__LoadIconA@8 referenced in function "void __cdecl RegisterWindowClass(struct HINSTANCE__ *)" (?RegisterWindowClass@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function "void __cdecl CreateAppWQindow(struct HINSTANCE__ *)" (?CreateAppWQindow@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__GetDesktopWindow@0 referenced in function "void __cdecl CreateAppWQindow(struct HINSTANCE__ *)" (?CreateAppWQindow@@YAXPAUHINSTANCE__@@@Z)
1>main.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function "unsigned int __cdecl StartMessageLoop(void)" (?StartMessageLoop@@YAIXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__PeekMessageA@20 referenced in function "unsigned int __cdecl StartMessageLoop(void)" (?StartMessageLoop@@YAIXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function "unsigned int __cdecl StartMessageLoop(void)" (?StartMessageLoop@@YAIXZ)
1>main.obj : error LNK2019: unresolved external symbol __imp__UpdateWindow@4 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl CreateAppWindow(struct HINSTANCE__ *)" (?CreateAppWindow@@YAXPAUHINSTANCE__@@@Z) referenced in function _WinMain@16
1>C:\Documents and Settings\PC\My Documents\Visual Studio 2005\Projects\fuckenwork\Debug\fuckenwork.exe : fatal error LNK1120: 15 unresolved externals
1>Build log was saved at "file://c:\My Documents\Visual Studio 2005\Projects\fuckenwork\fuckenwork\Debug\BuildLog.htm"
1>fuckenwork - 16 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
/
Can you tell me what i am doing wrong.

Share this post


Link to post
Share on other sites
Those are linker errors, you're forgetting to include the .lib file that defines all the functions inside windows.h... I think.

I forget what it's name is, I'll update this post with the name once I find it.

Share this post


Link to post
Share on other sites
You have linker errors. Specifically, the linker can't find the definitions of several Win32 APIs, which means either your development tools are set up wrong (so the linker can't find the static import libraries) or you're missing the installation of the PSDK (unlikely, since the files compile).

Also, you have a typo in there. I don't even know how that compiled, unless you didn't post the full error log...

Share this post


Link to post
Share on other sites

This topic is 3729 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this