5 Replies - 2622 Views - Last Post: 18 September 2012 - 05:43 AM Rate Topic: -----

#1 Poppa Mintin  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 13-September 08

WinAPI issue

Posted 16 September 2012 - 05:18 PM

View PostKYA, on 15 August 2008 - 10:39 PM, said:

#include <windows.h>

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
MessageBox(NULL, "Hello World!", "Dream in code", MB_OK);
return 0;
}


Here is your code as copied and pasted... Plus a few headers which are hangovers from trying various other code, I figure it's better to have #includes and not need them rather than need #includes and not have them. Trying to build the code without the extra bits makes no difference at all to the result. Two of them, "stdafx.h" and 'using namespace Win32Trial01;' are required by the compiler.
// Win32Trial 01.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
#include <string>
#include <WinUser.h>
#include <iostream> //For cout & cin

using namespace Win32Trial01;
using namespace std;

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev,  LPSTR lpCmd, int nShow)
{
    MessageBox(NULL, "Hello World!", "Dream in code", MB_OK);
    return 0;  
}


Here are the Error codes which my compiler(MS Visual C++ 2010) generates: -

Quote

1 error C2373: 'WinMain' : redefinition; different type modifiers
2 error C2872: 'MessageBox' : ambiguous symbol
3 error C2872: 'MessageBox' : ambiguous symbol


I've been hunting for a solution for about three hours or more without success so I've decided to bother you... To see if you can suggest what's going wrong.
I could post the entire build log, but I thought I'd just send the errors from the error list page for now.

My OS is Win.7 Pro. 64bit... fully up-dated.


Poppa.

Is This A Good Question/Topic? 0
  • +

Replies To: WinAPI issue

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3102
  • View blog
  • Posts: 19,142
  • Joined: 14-September 07

Re: WinAPI issue

Posted 16 September 2012 - 05:50 PM

Poppa,

I've split this off the tutorial and put it in the C++ help section where it will get more attention.

I'd recommend starting a blank project and adding the code. In all likelihood you have another main in Form1., but we'd need to see it.


All,

This question is in reference to this WinAPI tutorial.
Was This Post Helpful? 0
  • +
  • -

#3 rethc  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 76
  • Joined: 23-April 12

Re: WinAPI issue

Posted 17 September 2012 - 02:23 PM

Create a blank project

Then go to project menu> properties > linker dropdown > in subsystem select Windows

Add a new .cpp source file and copy the code from the tutorial.

This post has been edited by rethc: 17 September 2012 - 02:27 PM

Was This Post Helpful? 0
  • +
  • -

#4 Poppa Mintin  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 13-September 08

Re: WinAPI issue

Posted 17 September 2012 - 06:30 PM

View Postrethc, on 17 September 2012 - 03:23 PM, said:

Create a blank project
Then go to project menu> properties > linker dropdown > in subsystem select Windows
Add a new .cpp source file and copy the code from the tutorial.


Gave it my best shot...

Create a blank project: OK
Then go to project menu: OK
> properties: OK
> linker dropdown: OK
> in subsystem select Windows:

Linker Heading: 'Windows' Not found
Under Linker subheadings:
General:xxxxxtx 'Windows' Not found
Input:xxxxxxxxi 'Windows' Not found
Manifest File:xtix'Windows' Not found
Debugging:xxxxi'Windows' Not found
System:xxxxxxw'Windows' Not found
Optimization:xxx'Windows' Not found
Embedded IDL:|'Windows' Not found
Advanced: xxxxi'Windows' Not found
Command Line: 'Windows' Not found

Add a new .cpp source file and copy the code from the tutorial.

In Solution Explorer> Source Files:
Click 'Blank.ccp'
In (Global Scope)
Leave the // comment... Delete everything else.

Copy and paste code: Result: -
// Blank.cpp : main project file.
#include <windows.h>

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev,  LPSTR lpCmd, int nShow)
{
	MessageBox(NULL, "Hello World!", "Dream in code", MB_OK);
	return 0;	
}




Click 'Build':
Build Log:

Quote

| Output |
1>------ Build started: Project: Blank, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> Blank.cpp
1>Blank.cpp(2): warning C4627: '#include <windows.h>': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header
1>Blank.cpp(10): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Quote

| Error List |
/!\ 1 warning C4627: '#include <windows.h>': skipped when looking for precompiled header use
(x) 2 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?


Poppa.
Was This Post Helpful? 0
  • +
  • -

#5 rethc  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 76
  • Joined: 23-April 12

Re: WinAPI issue

Posted 17 September 2012 - 07:27 PM

I don't think you're creating a Blank Project, because you still have the stadfx.cpp and AssemblyInfo.cpp files. If the precompiled header tickbox is checked, untick it.
Posted Image

To add a source file to the project
Posted Image

The Windows subsystem is in the System subheader. I dont think this step is necessary but sometimes the compiler complains that there is no entry point. Select console if you want to make a console app.
Posted Image

This post has been edited by rethc: 17 September 2012 - 07:29 PM

Was This Post Helpful? 2
  • +
  • -

#6 Poppa Mintin  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 72
  • Joined: 13-September 08

Re: WinAPI issue

Posted 18 September 2012 - 05:43 AM

View Postrethc, on 17 September 2012 - 08:27 PM, said:

1. I don't think you're creating a Blank Project.
2. If the precompiled header tickbox is checked, untick it.
3. Add a source file to the project.
4. The Windows subsystem is in the System subheader. I dont think this step is necessary.


Well that's better, thanks :D

1. You were right, I didn't notice the 'Empty Project' option, I thought I was making 'My first Win32' program so I only saw 'Win32 Project'.

2. I couldn't find a 'Precompiled Header' tickbox so I had to disregard that.

3. I added an empty Source File.

4. I couldn't find the System sub-header, so I couldn't do it anyway.

I copied the code: -
// Blank.cpp : main project file.
#include <windows.h>

int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev,  LPSTR lpCmd, int nShow)
{
	MessageBox(NULL, "Hello World!", "Hello World", MB_OK);
	return 0;	
}

. . . into the blank source file and tried 'Build'... and the build succeded, so I ran it and the MessageBox did it's thing, and clicking ⌠ ok ⌡ worked !

Thank you again rethc.

Now for greater things...

Poppa.

This post has been edited by Poppa Mintin: 18 September 2012 - 05:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1