Visual C++ 2005

Started by
10 comments, last by disease332000 19 years, 2 months ago
I'm trying to start out using Microsoft Visual C++ 2005 Express Edition Beta (Really long title), and so I tried making a "Hello world" of sorts for the windows API:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow) {
	MessageBox(NULL, "Hello!", "Hello!", MB_OK);
}
When I build my "solution", I get the following error:

------ Build started: Project: Test, Configuration: Debug Win32 ------
Linking...
Main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function _WinMain@16
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Administrator\Desktop\Base\Code\2005\Test\Test\Debug\BuildLog.htm"
Test - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Whats wrong?
Advertisement
You need the Windows SDK from microsoft.com. But first, try this: #using mscorlib.dll

Phil
That was stupid.
Now I have installed the SDK, and, from the looks of my task manager, it leaked a bunch of memory. Or VC++ 2005 takes up a lot of memory. But I installed it all, the whole 1 gigabyte load, and I still get the error? What is wrong? What could I have done wrong?
Edit: Restarting... SOMETHING leaked a bitchload of memory.
Did you include the dll at the top? .NET compilers tend to take up quite a bit of memory.

#using <mscorlib.dll>
The compiler doesnt use up THAT much memory, looking at my task manager now. The leak I had a few seconds ago was like RAM at almost full usage. I have no idea what happened. I have tried doing #using at the top, but now I get another error:
------ Build started: Project: Test, Configuration: Debug Win32 ------Compiling...Main.cppc:\Documents and Settings\Administrator\Desktop\Base\Code\2005\Test\Test\Main.cpp(1) : fatal error C1190: managed targeted code requires a '/clr' optionBuild log was saved at "file://c:\Documents and Settings\Administrator\Desktop\Base\Code\2005\Test\Test\Debug\BuildLog.htm"Test - 1 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I tried adding "/clr" to the command line options (Under Project->Properties->C++->Command Line Options, as well as ->Linker->Command Line Options), but both got an error. What does "/clr" do?
As said in the Professional C# book, you can pass the flag /clr to the compiler which then assumes that you want to compile to managed code, and will hense emit IL instead of native machine code.

If nothing works, perhaps its because 2005 is still a beta. It should work under 2003 fine. No one knows about 2005 except MS, but it probably hasn't been implemented yet (or) not planned to. We won't know til MS releases the product. Someone may have a solution, but I ran out of ideas. Good luck.
Quote:Original post by phil05
Did you include the dll at the top? .NET compilers tend to take up quite a bit of memory.

#using <mscorlib.dll>


Quote:The DllImport attribute is very useful when reusing existing unmanaged code in a managed application. For instance, your managed application might need to make calls to the unmanaged WIN32 API.


I do not think the OP is writting managed code. If he was, the code would look like this. I think you need to link in the windows libraries. Take a look at this recent thread for the solution. It's the last post:
Quote:The files that made it work were: AdvAPI32.lib, GDI32.lib, User32.lib.


#include <windows.h>#pragma comment(lib,"AdvAPI32.lib")#pragma comment(lib,"GDI32.lib")#pragma comment(lib,"User32.lib")int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,				   LPSTR lpCmdLine, int nCmdShow) {	MessageBox(NULL, "Hello!", "Hello!", MB_OK);}

See if that code works. Hope this helps. Good luck!

- Drew
And there's that someone :) Interesting stuff.
Short answer: It works.
I couldn't open my libraries at first, but I just added an additional lib directory which points to the place where I installed the microsoft SDK. Is there any way that I can make this directory one of the "Project Defaults" that are mentioned in the settings? Also, is there any way that I can make some mythickal "Project Defaults" that make it so I don't have to #pragma comment those libs every time I make a new prog?
It's works good on Dev-C++,
But, when I compiled it with my VC++, an error being the linkers.

This topic is closed to new replies.

Advertisement