Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6012139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:21:38+00:00 2026-05-23T02:21:38+00:00

I have this compile error that I dont understand what is wrong. My Microsoft

  • 0

I have this compile error that I dont understand what is wrong. My Microsoft Visual Studio project is a Win32 Project (not console):

1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>C:\Users\Soribo\Desktop\C++ Programming\Visual C++ Programming\KeyboardHook\Release\KeyboardHook.exe : fatal error LNK1120: 1 unresolved externals

EDIT: After making #include “stdafx.h” as the 1st line the compile error is:

1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>C:\Users\Soribo\Desktop\C++ Programming\Visual C++ Programming\KeyboardHook\Release\KeyboardHook.exe : fatal error LNK1120: 1 unresolved externals

EDIT: hmm, I have defined WinMain function haven’t I? see below code:

/*
  Application: 
*/

#include <windows.h>
#include <cstdlib>
#include "stdafx.h"

using namespace std;

static HHOOK     keyboardHook;
static HINSTANCE gInstance;


// Functions List //
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam );
HHook ActivateKeyboardHook( HookProc hookProc, HINSTANCE hInstance );
bool DeactivateKeyboardHook( HHook keyboardHook );


int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
//int WINAPI WinMain( HINSTANCE gInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = gInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(DKGRAY_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = L"Custom Class";
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    // if registration of main class fails
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, L"Window Registration Failed!", L"Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        L"Custom Class",
        L"App Name",
        WS_CAPTION|WS_MINIMIZEBOX|WS_VISIBLE|WS_OVERLAPPED|WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 600, 500,
        NULL, NULL, gInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL, L"Window Creation Failed!", L"Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}

LRESULT CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{
    /*if ( code < 0 )
    {
        return CallNextHookEx( NULL, code, wParam, lParam );
    }*/  

    switch ( wParam )
    {
        case WM_KEYDOWN:
        {
            MessageBox( NULL, L"Notify", L"Key Down", MB_OK );        
        }
        break;
        case WM_KEYUP:
        {
            MessageBox( NULL, L"Notify", L"Key Up", MB_OK );                        
        }
        break;
        case WM_SYSKEYDOWN:
        {
            MessageBox( NULL, L"Notify", L"Sys Key Down", MB_OK );                        
        }
        break;
        case WM_SYSKEYUP:
        {
            MessageBox( NULL, L"Notify", L"Sys Key Up", MB_OK );                        
        }
        break;
        default:
        {
        } 
        break;
    }

    return CallNextHookEx( NULL, nCode, wParam, lParam );
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    switch(msg)
    {
        case WM_CREATE:
        {                  
             keyboardHook = ActivateKeyboardHook( &LowLevelKeyboardProc, gInstance );
        }    
        break;
        case WM_COMMAND:
        {
             switch(LOWORD(wParam)) 
             {

                  default:
                  break;
             }
        }
        break;
        case WM_CLOSE:
        {
            DeactivateKeyboardHook( keyboardHook );
            DestroyWindow(hwnd);
        }
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default: 
        break;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

HHOOK ActivateKeyboardHook( HookProc hookProc, HINSTANCE hInstance )
{
     return SetWindowsHookEx( WH_KEYBOARD_LL, hookProc, hInstance, 0 );
}

bool DeactivateKeyboardHook( HHook keyboardHook )
{
     return UnhookWindowsHookEx( keyboardHook );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:21:39+00:00Added an answer on May 23, 2026 at 2:21 am

    That is not compilation error, that is linker error, and it means your program doesn’t define WinMain function, which is entry point of the program.

    Make sure your program has this function:

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow);
    

    See this MSDN documentation:

    • WinMain: The Application Entry Point

    #include <windows.h>
    #include <cstdlib>
    #include "stdafx.h"
    

    If you’ve chosen precompiled header file, then the above is wrong, stdafx.h should be included at the beginning of the file. So change the order as:

    #include "stdafx.h"  //this should be first line of the program!
    #include <windows.h>
    #include <cstdlib>
    

    And I think you don’t need to include <windows.h> as most likely stdafx.h have included it already. Check it out.

    Now why should it be included first? Because precompiled header, as the name suggests, is a precompiled header. The compiler doesn’t compile it everytime. Instead, it compiles all the content in it once. If you don’t include it first, the compiler will not know that whether to compile the files included before it or not, because it may be that those files are already included in stdafx.h and so has already be compiled. See this topic:

    • include stdafx.h in header or source file? (at stackoverflow)
    • Use Precompiled Header File (at MSDN)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this source code from 2001 that I would like to compile. It
Challenge: I have this code that fails to compile. Can you figure out what's
Using Visual Studio 2008 and VB.Net: I have a working web app that uses
i have a code like this, but giving error can not access protected member.
I'm trying to compile the example visual studio solution that comes with the 3.2
I have 1 compiler error. It is from this line in my code: cout
i am a beginner and i have a problem : this code doesnt compile
I have a C++ driver I'm trying to compile, and it has this line
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
I have a Maven project that's building fine, and I'm attempting to add a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.