Won't compile a Windows program

G

Guest

I've been following the tutorial here to learn Windows programming (along
with the help file from the Windows Platform SDK):

http://www.cprogramming.com/tutorial/opengl_windows_programming.html

and when I try compiling the code given in this tutorial (even using copy
paste instead of manually typing it), I keep getting errors that prevent me
from compiling it. At first, it was because windows.h couldn't be found, but
that issue was resolved and now I've got one thing that is very confusing.
When I build, I get the error "unresolved external symbol". This is the
build log I get:

------ Build started: Project: Windowsapptest, Configuration: Debug Win32
------
Compiling...
firsttest.cpp
Linking...
firsttest.obj : error LNK2019: unresolved external symbol
__imp__MessageBoxA@16">__imp__MessageBoxA@16</a> referenced in function <a
href="mailto:_WinMain@16
C:\My Documents\My programs\Windowsapptest\Debug\Windowsapptest.exe : fatal
error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\My Documents\My
programs\Windowsapptest\Windowsapptest\Debug\BuildLog.htm"
Windowsapptest - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have Windows XP Pro SP2 and Visual C++ 2005 Express. From another forum,
I quite some help, but I was later told to ask elsewhere so I figured I'd
post here. You can see the details (and a few screenshots) here:

http://forums.howwhatwhy.com/showthreaded.php?Cat=&Board=software&Number=290240&page=&view=&sb=5&o=

How can I fix this?
 
W

William DePalo [MVP VC++]

ulillillia said:
I've been following the tutorial here to learn Windows programming (along
with the help file from the Windows Platform SDK):

http://www.cprogramming.com/tutorial/opengl_windows_programming.html

and when I try compiling the code given in this tutorial (even using copy
paste instead of manually typing it), I keep getting errors that prevent
me
from compiling it. At first, it was because windows.h couldn't be found,
but
that issue was resolved and now I've got one thing that is very confusing.
When I build, I get the error "unresolved external symbol". This is the
build log I get:

------ Build started: Project: Windowsapptest, Configuration: Debug Win32
------
Compiling...
firsttest.cpp
Linking...
firsttest.obj : error LNK2019: unresolved external symbol
__imp__MessageBoxA@16">__imp__MessageBoxA@16</a> referenced in function <a
href="mailto:_WinMain@16
C:\My Documents\My programs\Windowsapptest\Debug\Windowsapptest.exe :
fatal
error LNK1120: 1 unresolved externals

So, you call MessageBox() in your application? IAC, the linker is telling
you that it can't be found. Look up the function on the MSDN site. You find
the definition here:

http://msdn.microsoft.com/library/d...oxreference/dialogboxfunctions/messagebox.asp

Scroll down to the bottom of the page and you'll see that it requires the
USER32.LIB import library. Add that to the list of objects and libraries in
the linker's properties page and relink.

Of course, that presumes that you have downloaded the Windows software
development kit (SDK). Have you done that?

Regards,
Will
 
G

Guest

Yes, I have downloaded the Windows Platform SDK (R2) and installed it. I saw
that you need the user32.dll and/or user32.lib files. Thing is, how do you
link a library? An include?

Do note that I started with "empty project" or the like when I started this
temporary learning project. Much of the configuration stuff seems to be left
blank or empty. Don't bother mentioning to switch to "Win32 project" or
whatever as I don't have that available ("Windows console project" and
"Windows forms project" are the only two available). The only option I had
was to start with a empty project.
 
W

William DePalo [MVP VC++]

ulillillia said:
Yes, I have downloaded the Windows Platform SDK (R2) and installed it. I
saw
that you need the user32.dll and/or user32.lib files. Thing is, how do
you
link a library? An include?

You are using the Express Edition?

If so, choose Project->Properties from the menu. Click on the '+' to expand
the 'Configuration Properties', then open up the 'Linker' options the same
way, click on the 'Input' category, then in the edit box labeled 'Additional
Depencies' type

user32.lib

Regards,
Will
 
W

Wyvern

You should do like below steps:

Update the Visual C++ directories in the Projects and Solutions section in the Options dialog box.

Add the paths to the appropriate subsection:

Executable files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin

Include files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include

Library files: C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib

Note: Alternatively, you can update the Visual C++ Directories by modifying the VCProjectEngine.dll.express.config file located in the \vc\vcpackages subdirectory of the Visual C++ Express install location. Please make sure that you also delete the file "vccomponents.dat" located in the "%USERPROFILE%\Local Settings\Application Data\Microsoft\VCExpress\8.0" if it exists before restarting Visual C++ Express Edition.



Update the corewin_express.vsprops file.

One more step is needed to make the Win32 template work in Visual C++ Express. You need to edit the corewin_express.vsprops file (found in C:\Program Files\Microsoft Visual Studio 8\VC\VCProjectDefaults) and

Change the string that reads:

AdditionalDependencies="kernel32.lib" to

AdditionalDependencies="kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib"



Generate and build a Win32 application to test your paths.

In Visual C++ Express, the Win32 Windows Application type is disabled in the Win32 Application Wizard. To enable that type, you need to edit the file AppSettings.htm file located in the folder ¡°%ProgramFiles%\Microsoft Visual Studio 8\VC\VCWizards\AppWiz\Generic\Application\html\1033\".

In a text editor comment out lines 441 - 444 by putting a // in front of them as shown here:

// WIN_APP.disabled = true;
// WIN_APP_LABEL.disabled = true;
// DLL_APP.disabled = true;
// DLL_APP_LABEL.disabled = true;

Save and close the file and open Visual C++ Express.

From the File menu, click New Project. In the New Project dialog box, expand the Visual C++ node in the Product Types tree and then click Win32. Click on the Win32 Console Application template and then give your project a name and click OK. In the Win32 Application Wizard dialog box, make sure that Windows application is selected as the Application type and the ATL is not selected. Click the Finish button to generate the project.

As a final step, test your project by clicking the Start button in the IDE or by pressing F5. Your Win32 application should build and run.


--------------------------------------------------------------------------------


"William DePalo [MVP VC++]" <[email protected]> дÈëÏûÏ¢
ulillillia said:
Yes, I have downloaded the Windows Platform SDK (R2) and installed it. I
saw
that you need the user32.dll and/or user32.lib files. Thing is, how do
you
link a library? An include?

You are using the Express Edition?

If so, choose Project->Properties from the menu. Click on the '+' to expand
the 'Configuration Properties', then open up the 'Linker' options the same
way, click on the 'Input' category, then in the edit box labeled 'Additional
Depencies' type

user32.lib

Regards,
Will
 
G

Guest

I'm very confused with the first part - setting the directories. I don't see
any of the "C:\Program Files\..." stuff, but other things that makes me very
confused. As an example, I see this in that file you mentioned:

Include="$(VCInstallDir)include;$(VCInstallDir)PlatformSDK\include;$(FrameworkSDKDir)include"

I don't get what any of this means and as a result, I have no idea what I
need to do. I first used the options dialog stuff, but I saw this same thing
without the familiar "C:\Program Files\..." stuff. What do I do and where do
I put the additions I need. I don't see any "executable files" listed in
that file. Given the top line, it appears as if this is an XML file, the
first time I've actually seen such a file (which seems a lot like HTML only
with odd symbols and formatting (the dollar sign)).

I haven't done anything else past this first part since I feel as if I need
to do them in the order you've given.

Thanks so far though for the assistance, but I'm just very confused on the
first part I need to do.
 
G

Guest

Okay, so I tried just copying and pasting the URL using the dialog through
the options menu instead of being confused with the weird formatting. That
appeared to have worked properly and I began following the other directions
you had and it all works. Thank you so much for the assistance and I can now
begin learning Windows programming and eventually get into game programming
when my ability gets good enough.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top