-
Missing library
I'm learning windows game programming from a book. Anyway for one of the game examples, it wants me to change the linker setting to include: msimg32.lib
It tells me to look in the lib folder that comes with my compiler. However I've looked in the lib folders of the two different compilers I have and that file isn't in either. Am I missing the point of what to do here. If not where can I get this file. None of the game examples will compile without it.
Thanks
-
search your computer for it,
or i can mail it to ya.
-
It comes with VC++ 6.0, Visual Studio .NET 2003, and the free with current version of Windows SDK
-
Whenever i need a library, i just search my Visual Studio folder, it's always there.
-
Ok, thanks for that. Having searched my comp for it I've just discovered that It was in lib file all along, I just didn't see it.
Any I've now got a new problem. One of the examples uses two functions: max() and min()
When I try to comile however I get:
"ufo.cpp": E2268 Call to undefined function 'max' in function HandleKeys() at line 84
The thing is the book comes with a source code disk and I have litteraly inported the project from the disk. As they seem to to be missing from the main code, and the book says nothing about them, I'm stuck what to do. Unless anyone knows where they are defined or can help me get round the problem.
Just incase it helps, I've included how they are used:
Code:
void GameCycle()
{
// Update the saucer position
g_iSaucerX = min(500 - g_pSaucer->GetWidth(), max(0, g_iSaucerX + g_iSpeedX));
g_iSaucerY = min(320, max(0, g_iSaucerY + g_iSpeedY));
// Force a repaint to redraw the saucer
InvalidateRect(g_pGame->GetWindow(), NULL, FALSE);
}
void HandleKeys()
{
// Change the speed of the saucer in response to arrow key presses
if (GetAsyncKeyState(VK_LEFT) < 0)
g_iSpeedX = max(-g_iMAXSPEED, --g_iSpeedX);
else if (GetAsyncKeyState(VK_RIGHT) < 0)
g_iSpeedX = min(g_iMAXSPEED, ++g_iSpeedX);
if (GetAsyncKeyState(VK_UP) < 0)
g_iSpeedY = max(-g_iMAXSPEED, --g_iSpeedY);
else if (GetAsyncKeyState(VK_DOWN) < 0)
g_iSpeedY = min(g_iMAXSPEED, ++g_iSpeedY);
}
Thanks in advance.
-
that looks like it was just intended to be included in another project, it doesn't look like it should be used by itself.
-
Code:
#define max(a, b) (((a) > (b)) ? (a) : (b))
Its defined like the above
-
Wraithan: No, thats part of the code from the source code for one of the complete games. I can't see why the book has suppliedcode that won't even compile.
Ancient Dragon: I added that code and its done nothing, was I just supposed to add that, or am I missing something here.
Sorry to keep asking questions but this example is really annoying me and I want it to compile.
Thanks
-
you should not use a macro to evaluate max like the one I posted previously because it will evaluate the expression more than once causing "--g_iSpeedX" to be executed twice. Write a small function to avoid that problem
Both these functions must appear before any of the other code you posted. They assume they are evaluating integers. You might have to change the integers to some other data type, such as whetver g_iSaucerX is. Since this is a c++ board I'm sure someone else can write a simple template to take care of any data type.
Code:
int max(int a, int b)
{
return (a > b) ? a : b;
}
int min(int a, int b)
{
return (a > b) ? b : a;
}
-
Thank you all.
After fixing that successfully, and another 3 problems after that I've finally got all working as it should be. Thanks a lot for everyone thats helped