unresolved external symbol
I dicided to rewrite my base code that I use for written OpenGL programs but I have one unresolved external symbol if you can find it and tell me plz do here is the error I get i feel dumb because it has to be simple and it just wont work. The code is what i have learned form opengl game programming gametutorials here and the red book
init.obj : error LNK2001: unresolved external symbol "long __stdcall WinProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WinProc@@YGJPAUHWND__@@IIJ@Z)
Debug/beta1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
beta1.exe - 2 error(s), 1 warning(s)
and all of the code
(main.h)
#include <windows.h>
#include <gl.h>
#include <glu.h>
extern HDC g_HDC;
extern width;
extern height;
extern bits;
extern fullScreen;
extern HWND hwnd;
extern MSG msg;
extern dwExStyle;
extern dwStyle;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hprev, PSTR cmdline, int ishow);
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void SetupPixelFormat(HDC hDC);
WPARAM mainLoop();
void render();
(main.cpp)
#include "main.h"
int fullScreen = true;
bool done=false;
HDC g_HDC;
MSG msg;
HWND hwnd;
WPARAM mainLoop()
{
while (done)
{
PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);
if (msg.message == WM_QUIT)
{
done = true;
}
else
{
render();
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if(fullScreen)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(TRUE);
}
return msg.wParam;
}
(init)
#include "main.h"
void SetupPixelFormat(HDC hDC)
{
int nPixelFormat;
static PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0,};
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, nPixelFormat, &pfd);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASSEX windowClass;
HWND hwnd;
MSG msg;
DWORD dwExStyle;
DWORD dwStyle;
RECT windowRect;
int width = 800;
int height = 600;
int bits = 32;
windowRect.left=(long)0;
windowRect.right=(long)width;
windowRect.top=(long)0;
windowRect.bottom=(long)height;
windowClass.cbSize =sizeof(WNDCLASSEX);
windowClass.style =CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc =WinProc;
windowClass.cbClsExtra =0;
windowClass.cbWndExtra =0;
windowClass.hInstance =hInstance;
windowClass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
windowClass.hCursor =LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground =NULL;
windowClass.lpszMenuName =NULL;
windowClass.lpszClassName ="beta";
windowClass.hIconSm =LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&windowClass))
{
MessageBox(NULL,"could not register class", NULL, MB_OK);
return 0;
}
if (fullScreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) !=
DISP_CHANGE_SUCCESSFUL)
{
MessageBox(NULL,"Display mode failed", NULL, MB_OK);
fullScreen=FALSE;
}
if (fullScreen)
{
dwExnostyle=WS_EX_APPWINDOW;
dwnostyle=WS_POPUP;
ShowCursor(FALSE);
}
}
if (!fullScreen)
{
dwExnostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwnostyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRect(&windowRect, dwStyle,FALSE);
hwnd = CreateWindowEx(NULL, "MyClass",
"Beta",
dwStyle | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
0, 0,
windowRect.right - windowRect.left,
windowRect.bottom - windowRect.top,
NULL,
NULL,
hInstance,
NULL);
if (!hwnd)
return 0;
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return mainLoop();
}
(input.cpp)
#include "main.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HGLRC hRC;
static HDC hDC;
int width, height;
switch(message)
{
case WM_CREATE:
hDC=GetDC(hwnd);
g_HDC = hDC;
SetupPixelFormat(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
return 0;
break;
case WM_CLOSE:
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
PostQuitMessage(0);
return 0;
break;
case WM_SIZE:
height = HIWORD(lParam);
width = LOWORD(lParam);
if (height==0)
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return 0;
break;
default:
break;
}
return (DefWindowProc(hwnd,message, wParam, lParam));
}
(render)
#include "main.h"
void render()
{
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glColor3f(0.0,0.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(0.0,0.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(2.0,0.0,0.0);
glEnd();
glFlush();
SwapBuffers(g_HDC);
}
Did you remember to add "input.cpp" to your project? That error means the linker wasn''t able find the WndProc function.
Here''s a tip regarding code listings of more the 3 or 4 lines. Wrap them in {source} {/source} tags - but replace {} with []. Thus:
Here''s a tip regarding code listings of more the 3 or 4 lines. Wrap them in {source} {/source} tags - but replace {} with []. Thus:
(main.h)#include <windows.h>#include <gl.h>#include <glu.h>extern HDC g_HDC;extern width;extern height;extern bits;extern fullScreen;extern HWND hwnd;extern MSG msg;extern dwExStyle;extern dwStyle;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hprev, PSTR cmdline, int ishow);LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);void SetupPixelFormat(HDC hDC);WPARAM mainLoop();void render();(main.cpp)#include "main.h"int fullScreen = true;bool done=false;HDC g_HDC;MSG msg;HWND hwnd;WPARAM mainLoop(){while (done){PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);if (msg.message == WM_QUIT){done = true;}else{render();TranslateMessage(&msg);DispatchMessage(&msg);}}if(fullScreen){ChangeDisplaySettings(NULL, 0);ShowCursor(TRUE);}return msg.wParam;}(init)#include "main.h"void SetupPixelFormat(HDC hDC){int nPixelFormat;static PIXELFORMATDESCRIPTOR pfd = {sizeof(PIXELFORMATDESCRIPTOR),1,PFD_DRAW_TO_WINDOW |PFD_SUPPORT_OPENGL |PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE,0,0,0,0,};nPixelFormat = ChoosePixelFormat(hDC, &pfd);SetPixelFormat(hDC, nPixelFormat, &pfd);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd){WNDCLASSEX windowClass;HWND hwnd;MSG msg;DWORD dwExStyle;DWORD dwStyle;RECT windowRect;int width = 800;int height = 600;int bits = 32;windowRect.left=(long)0;windowRect.right=(long)width;windowRect.top=(long)0;windowRect.bottom=(long)height;windowClass.cbSize =sizeof(WNDCLASSEX);windowClass.style =CS_HREDRAW | CS_VREDRAW;windowClass.lpfnWndProc =WinProc;windowClass.cbClsExtra =0;windowClass.cbWndExtra =0;windowClass.hInstance =hInstance;windowClass.hIcon =LoadIcon(NULL,IDI_APPLICATION);windowClass.hCursor =LoadCursor(NULL, IDC_ARROW);windowClass.hbrBackground =NULL;windowClass.lpszMenuName =NULL;windowClass.lpszClassName ="beta";windowClass.hIconSm =LoadIcon(NULL, IDI_WINLOGO);if(!RegisterClassEx(&windowClass)){MessageBox(NULL,"could not register class", NULL, MB_OK);return 0;}if (fullScreen){DEVMODE dmScreenSettings;memset(&dmScreenSettings,0,sizeof(dmScreenSettings));dmScreenSettings.dmSize = sizeof(dmScreenSettings);dmScreenSettings.dmPelsWidth = width;dmScreenSettings.dmPelsHeight = height;dmScreenSettings.dmBitsPerPel = bits;dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) !=DISP_CHANGE_SUCCESSFUL){MessageBox(NULL,"Display mode failed", NULL, MB_OK);fullScreen=FALSE;}if (fullScreen){dwExnostyle=WS_EX_APPWINDOW;dwnostyle=WS_POPUP;ShowCursor(FALSE);}}if (!fullScreen){dwExnostyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;dwnostyle=WS_OVERLAPPEDWINDOW;}AdjustWindowRect(&windowRect, dwStyle,FALSE);hwnd = CreateWindowEx(NULL, "MyClass","Beta",dwStyle | WS_CLIPCHILDREN |WS_CLIPSIBLINGS,0, 0,windowRect.right - windowRect.left,windowRect.bottom - windowRect.top,NULL,NULL,hInstance,NULL);if (!hwnd)return 0;ShowWindow(hwnd, SW_SHOW);UpdateWindow(hwnd);return mainLoop();}(input.cpp)#include "main.h"LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){static HGLRC hRC;static HDC hDC;int width, height;switch(message){case WM_CREATE:hDC=GetDC(hwnd);g_HDC = hDC;SetupPixelFormat(hDC);hRC = wglCreateContext(hDC);wglMakeCurrent(hDC,hRC);return 0;break;case WM_CLOSE:wglMakeCurrent(hDC, NULL);wglDeleteContext(hRC);PostQuitMessage(0);return 0;break;case WM_SIZE:height = HIWORD(lParam);width = LOWORD(lParam);if (height==0){height=1;}glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(54.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();return 0;break;default:break;}return (DefWindowProc(hwnd,message, wParam, lParam));}(render)#include "main.h"void render(){glEnable(GL_DEPTH_TEST);glClearColor(0.0f,0.0f,0.0f,0.0f);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glColor3f(0.0,0.0,1.0);glBegin(GL_POLYGON);glVertex3f(0.0,0.0,0.0);glVertex3f(1.0,1.0,0.0);glVertex3f(2.0,0.0,0.0);glEnd();glFlush();SwapBuffers(g_HDC);}
You have named the function 2 different names. In Main.h you have it defined as
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
but in input.cpp you named it
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
WinProc is not the same as WndProc. Change it to WndProc in the Main.h file and it should work.
LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
but in input.cpp you named it
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
WinProc is not the same as WndProc. Change it to WndProc in the Main.h file and it should work.
i found it about a sec befor you told me thx for telling me
so how do you condese the code to the scroll
so how do you condese the code to the scroll
You simply have two WndProcs with the same scope: one in main.cpp and one in input.cpp. It has nothing to do with giving them two different names, or any missing.
Visual C++ uses name decoration to distinguish between variables and functions that have the same name but different scope . The unresolved external error was raised because these two functions of the same name have global scope.
To resolve this error, you will need to eliminate one of them, preferably the one in input.cpp in fitting with convention.
Regards,
Mathematix.
[edited by - mathematix on July 28, 2002 10:26:49 PM]
Visual C++ uses name decoration to distinguish between variables and functions that have the same name but different scope . The unresolved external error was raised because these two functions of the same name have global scope.
To resolve this error, you will need to eliminate one of them, preferably the one in input.cpp in fitting with convention.
Regards,
Mathematix.
[edited by - mathematix on July 28, 2002 10:26:49 PM]
omega arts, add "code" at the beginning of the block you want to make into the fun scrolly window, and "/code" at the end (but make sure to use [] brackets instead of quotation marks).
that fixed all the errors but now when i run the program it goes to a black screen then goes back to VC++ and does not run
is this a opengl problem or a c++ problem
[edited by - omega arts on July 28, 2002 10:47:36 PM]
is this a opengl problem or a c++ problem
[/how do you get this to work ]
[edited by - omega arts on July 28, 2002 10:47:36 PM]
quote:Original post by Anonymous Poster
omega arts, add "code" at the beginning of the block you want to make into the fun scrolly window, and "/code" at the end (but make sure to use [] brackets instead of quotation marks).
Incorrect. Use "code" to preserve spacing, use "source" to place the code in a white block with scroll bars. And to prevent the #include directives from bunching up double space them inside the block
#include <windows.h>#include <stdio.h>#include <math.h>#include <windows.h>#include <stdio.h>#include <math.h>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement