back again with another question.

i created a simple window in WIN32 mode, but it's giving me a linker error that i cannot isolate.

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


//defined this for all processes
HINSTANCE hInstance;

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam); //WndProc Prototype. always use this

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wc; //identifiers for the window

	ZeroMemory(&wc,sizeof(WNDCLASSEX)); //

	wc.cbClsExtra= NULL;					//additional paramiters
	wc.cbSize= sizeof(WNDCLASSEX);			//size of the window class
	wc.cbWndExtra= NULL;					//aditional window paramiters
	wc.hbrBackground= (HBRUSH)COLOR_WINDOW;	//background color of the window
	wc.hCursor= LoadCursor(NULL,IDC_ARROW);	//window cursor
	wc.hIcon= NULL;							//window icon
	wc.hIconSm= NULL;						//small window icon
	wc.hInstance= hInstance;				//application instance
	wc.lpfnWndProc= ( WNDPROC)WinProc;		//callback proc.
	wc.lpszClassName= _T("Window Class");	//class name
	wc.lpszMenuName= NULL;					//menu name
	wc.style= CS_HREDRAW|CS_VREDRAW;		//window styles

	RegisterClassEx(&wc); //register the class

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, _T("Classs registration failure error!"), _T("Execution Runtime Error"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	HWND hWnd = CreateWindowEx(NULL, _T("Window Class"), _T("Program Name"), WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInstance, NULL); //create the window
	if(!hWnd)
	{
		int nResult=GetLastError();

		MessageBox(NULL, _T("Window creation failed"), _T("Window Creation Failed"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	ShowWindow(hWnd,nShowCmd); // show the window
	UpdateWindow(hWnd); //update the window
	MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg); //translate message data
        DispatchMessage(&msg); //throw a dispatch call to WinProc
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR greeting[] = _T("Does this work now?");

    switch (msg)
    {
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        // Here the  application is laid out.
        TextOut(hdc,
            5, 5,
            greeting, _tcslen(greeting));
        

        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
        break;
    }

    return 0;
}

error:
lNK2019: unresolved external symbol "long __stdcall WinProc(struct HWND__ *,unsigned int,long,unsigned int)"

any ideas? i probably missed something somewhere, but idk. :/

Recommended Answers

All 6 Replies

back again with another question.

i created a simple window in WIN32 mode, but it's giving me a linker error that i cannot isolate.

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


//defined this for all processes
HINSTANCE hInstance;

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam); //WndProc Prototype. always use this

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wc; //identifiers for the window

	ZeroMemory(&wc,sizeof(WNDCLASSEX)); //

	wc.cbClsExtra= NULL;					//additional paramiters
	wc.cbSize= sizeof(WNDCLASSEX);			//size of the window class
	wc.cbWndExtra= NULL;					//aditional window paramiters
	wc.hbrBackground= (HBRUSH)COLOR_WINDOW;	//background color of the window
	wc.hCursor= LoadCursor(NULL,IDC_ARROW);	//window cursor
	wc.hIcon= NULL;							//window icon
	wc.hIconSm= NULL;						//small window icon
	wc.hInstance= hInstance;				//application instance
	wc.lpfnWndProc= ( WNDPROC)WinProc;		//callback proc.
	wc.lpszClassName= _T("Window Class");	//class name
	wc.lpszMenuName= NULL;					//menu name
	wc.style= CS_HREDRAW|CS_VREDRAW;		//window styles

	RegisterClassEx(&wc); //register the class

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, _T("Classs registration failure error!"), _T("Execution Runtime Error"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	HWND hWnd = CreateWindowEx(NULL, _T("Window Class"), _T("Program Name"), WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInstance, NULL); //create the window
	if(!hWnd)
	{
		int nResult=GetLastError();

		MessageBox(NULL, _T("Window creation failed"), _T("Window Creation Failed"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	ShowWindow(hWnd,nShowCmd); // show the window
	UpdateWindow(hWnd); //update the window
	MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg); //translate message data
        DispatchMessage(&msg); //throw a dispatch call to WinProc
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR greeting[] = _T("Does this work now?");

    switch (msg)
    {
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        // Here the  application is laid out.
        TextOut(hdc,
            5, 5,
            greeting, _tcslen(greeting));
        

        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
        break;
    }

    return 0;
}

error:
lNK2019: unresolved external symbol "long __stdcall WinProc(struct HWND__ *,unsigned int,long,unsigned int)"

any ideas? i probably missed something somewhere, but idk. :/

Your prototype WinProc is spelled different from the function WndProc. And also, the parameter list for both is different!

back again with another question.

i created a simple window in WIN32 mode, but it's giving me a linker error that i cannot isolate.

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


//defined this for all processes
HINSTANCE hInstance;

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam); //WndProc Prototype. always use this

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	WNDCLASSEX wc; //identifiers for the window

	ZeroMemory(&wc,sizeof(WNDCLASSEX)); //

	wc.cbClsExtra= NULL;					//additional paramiters
	wc.cbSize= sizeof(WNDCLASSEX);			//size of the window class
	wc.cbWndExtra= NULL;					//aditional window paramiters
	wc.hbrBackground= (HBRUSH)COLOR_WINDOW;	//background color of the window
	wc.hCursor= LoadCursor(NULL,IDC_ARROW);	//window cursor
	wc.hIcon= NULL;							//window icon
	wc.hIconSm= NULL;						//small window icon
	wc.hInstance= hInstance;				//application instance
	wc.lpfnWndProc= ( WNDPROC)WinProc;		//callback proc.
	wc.lpszClassName= _T("Window Class");	//class name
	wc.lpszMenuName= NULL;					//menu name
	wc.style= CS_HREDRAW|CS_VREDRAW;		//window styles

	RegisterClassEx(&wc); //register the class

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL, _T("Classs registration failure error!"), _T("Execution Runtime Error"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	HWND hWnd = CreateWindowEx(NULL, _T("Window Class"), _T("Program Name"), WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInstance, NULL); //create the window
	if(!hWnd)
	{
		int nResult=GetLastError();

		MessageBox(NULL, _T("Window creation failed"), _T("Window Creation Failed"), MB_OK | MB_ICONEXCLAMATION);
		return 1;
	}

	ShowWindow(hWnd,nShowCmd); // show the window
	UpdateWindow(hWnd); //update the window
	MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg); //translate message data
        DispatchMessage(&msg); //throw a dispatch call to WinProc
    }

    return (int) msg.wParam;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR greeting[] = _T("Does this work now?");

    switch (msg)
    {
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);

        // Here the  application is laid out.
        TextOut(hdc,
            5, 5,
            greeting, _tcslen(greeting));
        

        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
        break;
    }

    return 0;
}

error:
lNK2019: unresolved external symbol "long __stdcall WinProc(struct HWND__ *,unsigned int,long,unsigned int)"

any ideas? i probably missed something somewhere, but idk. :/

Also, don't forget to make sure the "WndProc" name in your WNDCLASSEX struct (line 25) matches the name of the other two "WndProc"s

thanks. had no idead i did that. maybe VS should come with spell checker....

i created a simple programe in win32 apllication, but it's giving me a linker error:

#include <stdio.h>
int main ()
{
    int A,B,C;
    printf("please enter two values");
    scanf("%d%d",&A,&B);
    C=A+B;
    printf("the sum of %d and %d is %d",A,B,C);
    return 0;
}

EROOR:
LINK : fatal error LNK1104: cannot open file "Debug/papa.exe"
Error executing link.exe.

do u please have any idea about this because as you can see i am a beginner

i created a simple programe in win32 apllication, but it's giving me a linker error:

LINK : fatal error LNK1104: cannot open file "Debug/papa.exe"

do u please have any idea about this because as you can see i am a beginner

Chances are, "Debug/papa.exe" is still open. That is the program you wrote. Is it still running? You need to make sure that window is closed so papa isn't running any more. Otherwise, try shutting down your IDE (compiler) and restart it.

actually when i compile it it gives me neither warning nor error but when i run it a window tells me "this file does not exist.do you want to build it?"
I click on yes and than it give me "LINK : fatal error LNK1104: cannot open file "Debug/Text187.exe""

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.