Unresolved external symbols?

Started by
23 comments, last by EGD Eric 20 years, 7 months ago
1) Fired up dev studio 2002 Professional
2) File/New/Project
3) Selected C++/Win32 Project, Name: OpenGlTest, Location: C:\Source Code\C++\Test, then OK
4) Hit Application Settings, checked empty project, hit Finish
5) Right mouse on the project, Add/New Item, highlighted "C++ File", Name: OpenGlTest.cpp, hit Open
6) Pasted your code in (the code from your first post).
7) Right mouse click on the project select Properties, changed the configuration to be "All Configurations"
8) In the tree select Configuration Properties/Linker/Input. In the first field "Additional Dependencies" put:
opengl32.lib glu32.lib
9) hit OK
10) Hit F5 to run. Program exits early. Tracing in the debugger shows that RegisterClassEx is failing.
11) Fix the typo at line 115:
    windowClass.style = sizeof(WNDCLASSEX);  

to be
    memset( &windowClass, 0, sizeof(WNDCLASSEX) );    windowClass.cbSize = sizeof(WNDCLASSEX);  

in addition to zero initializing the structure. I also add a windows class name that matches the one in the CreateWindow() call:
    windowClass.lpszClassName = "MyClass";  

12) I hit F5 and rebuild and it now runs.



[edited by - mauman on August 20, 2003 3:26:20 PM]
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }
Advertisement
In C++ builder 5, (includes opengl and stuff useing some weird mechanism on its own...)

I took first post code pasted it into a blank .cpp file.
changed the

windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.cbWndExtra = 0;
windowClass.lpszClassName = "MyClass";
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default icon
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrow
windowClass.hbrBackground = NULL; //don''t need background
windowClass.lpszMenuName = NULL; //no menu

to be as it reads above, reloaded it to make a project file. hit run, it ran.

it shows a nifty red triangle rotating around the central z axis..

Before I changed the befoce code, it ran and closed itself with out doing anything. so in essence it did nothing.
"I seek knowledge and to help those who also seek it"
Time to learn how to program instead of copying and pasting.

Why you shouldn''t use iostream.h - ever! | A Good free online C++ book
If you want to save time, skip the first 2 paragraphs.
They are directed at Siaspete and Trienco.

Actually, I already know how to program. I'm just wet around the ears. I've already have a good grasp of the C++ language. I once made a 2-player chess program in C that was a bitch for me to debug (at the time). I've done file writing, operator overloading and templated linked lists, among other things. I've only worked in simple console before. When I learn something new, I like to start off with theory, then mimicking (copying and pasting) then tweaking with it, then More theory, then either repeat the steps or do whatever else I decide to do.
As I go, I use less and less "Crutches". This may not be how you learn, but its how I learn. You may have taught yourself, but ALL of MY programming skill comes from school. I just finished my first year, before which I didn't know much at all about computers.

Don't take your knowledge for granted. Some people just aren't as knowledgable and/or possessing as much "Computer sense" as you do. It doesn't mean I'm taking shortcuts or being lazy, its because its the only way I know how for now. If you can tell me a better way of doing it, maybe I'll try that.


I've implemented the changes in the C++6 project and it still exits early. This happens at line 131:

if(!RegisterClassEx(&windowClass))
return 0;

it seems to register the class okay, but then it skips
to the bottom line of this function call:

hwnd = CreateWindowEx(NULL,//extended style "MyClass",//class name "The OpenGL Window Application!",//app name
WS_OVERLAPPEDWINDOW | WS_VISIBLE| //window style
WS_SYSMENU | WS_CLIPCHILDREN | //
WS_CLIPSIBLINGS,
100, 100,//x, y coordinate
400, 400,//width, height
NULL, //handle to parent
NULL, //handle to menu
hInstance, //application instance
NULL); //no extra parameters

At this point hwnd is still NULL, which means it must not have Created the window. I can't step into the CreateWindowEx function because the compiler skips the lines for some reason.

if(!hwnd)
return 0;
This is where the program ends.

I tried this with C++6.

I'm gonna look into the .net development environment now, read the docs and stuff.


Edit: I just ran into something on the .net docs!
Its a Direct 3D tutorial! It showed the CreateWindow function, instead of the CreateWindowEx function, I tried this and it worked!

hwnd = CreateWindow("My Class", "The OpenGL Window Application!", WS_OVERLAPPEDWINDOW,
100, 100, 400, 400, GetDesktopWindow(), NULL, windowClass.hInstance, NULL);

[edited by - EGD Eric on August 21, 2003 2:37:34 PM]
If you use the same code from before you had two bugs in your window class code which may have caused your CreateWindow() call to fail. One was your window class name was missing. This is what the 1st argument to CreateWindow and the 2nd argument to CreateWindowEx use to find the class you registered. Second, you were setting the stype field to be the structure size not the cbSize field. Aslo, you should zero initialize your structures in windows in case you do not explicitly set all of the fields.

With that said your registration code should look like:
//fill out the window class structurememset( &windowClass, 0, sizeof(WNDCLASSEX));windowClass.cbSize = sizeof(WNDCLASSEX);windowClass.lpszClassName = "MyClass";windowClass.style = CS_HREDRAW | CS_VREDRAW;windowClass.lpfnWndProc = WndProc;windowClass.cbClsExtra = 0;windowClass.cbWndExtra = 0;windowClass.cbWndExtra = 0;windowClass.hInstance = hInstance;windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default iconwindowClass.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrowwindowClass.hbrBackground = NULL; //don't need backgroundwindowClass.lpszMenuName = NULL; //no menu//Register the window classif(!RegisterClassEx(&windowClass))   return 0;


You should find that this works on VC6, VC7 (Visual Studio .Net 2002), and VC7.1 (Visual Studio .Net 2003)


[edited by - mauman on August 21, 2003 4:24:31 PM]
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }

This topic is closed to new replies.

Advertisement