| View previous topic :: View next topic |
| Author |
Message |
sotaukko Cheater
Reputation: 0
Joined: 23 Oct 2007 Posts: 32
|
Posted: Tue Oct 21, 2008 11:27 am Post subject: [Noob Question]WIN32 API Compiling error. |
|
|
Ok. I've been learning C++ for some time now and i started learning Win32 APIs yesterday. Here is my source(Probably simpliest Win32 source)
Source(In Main.cpp)
| Code: | #include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MessageBox(NULL, "Goodbye", "Note", MB_OK);
return 0;
} |
when i try to compile it im getting this errors:
Error:
| Code: | error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast |
So is the source bad or am i missing some files or perhaps something else?
Last edited by sotaukko on Wed Oct 22, 2008 7:08 am; edited 1 time in total |
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Tue Oct 21, 2008 11:51 am Post subject: |
|
|
| Use either unicode strings or compile in ANSI.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Tue Oct 21, 2008 11:54 am Post subject: |
|
|
When you want to do unicode strings, prefix them with L
For example:
| Code: |
MessageBox(NULL, L"Goodbye", L"Note", MB_OK);
|
If you don't want to, you could either use MessageBoxA, which is the ANSI variant of MessageBox, or you could choose for ANSI at project options, which will automatically choose MessageBoxA for you when you type MessageBox.
|
|
| Back to top |
|
 |
sotaukko Cheater
Reputation: 0
Joined: 23 Oct 2007 Posts: 32
|
Posted: Tue Oct 21, 2008 12:12 pm Post subject: |
|
|
| tombana wrote: | When you want to do unicode strings, prefix them with L
For example:
| Code: |
MessageBox(NULL, L"Goodbye", L"Note", MB_OK);
|
If you don't want to, you could either use MessageBoxA, which is the ANSI variant of MessageBox, or you could choose for ANSI at project options, which will automatically choose MessageBoxA for you when you type MessageBox. |
Sorry but were i can toggle ANSI on. I checked options and project options but couldn't find anything releated to ANSI. (Im using Microsoft Visual C++ Express edition)
|
|
| Back to top |
|
 |
nog_lorp Grandmaster Cheater
Reputation: 0
Joined: 26 Feb 2006 Posts: 743
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Tue Oct 21, 2008 1:07 pm Post subject: |
|
|
| Code: | | MessageBoxA(NULL, "Goodbye", "Note", MB_OK); |
or
| Code: | #include <tchar.h>
MessageBox(NULL, _T("Goodbye"), _T("Note"), MB_OK); |
|
|
| Back to top |
|
 |
SFP+ Comp. talk moderator
Reputation: 26
Joined: 02 May 2007 Posts: 1228 Location: Sweden
|
Posted: Tue Oct 21, 2008 1:44 pm Post subject: |
|
|
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Tue Oct 21, 2008 2:43 pm Post subject: |
|
|
| Safko wrote: |  |
Do what TraxMate did instead. The _T macro will just format the string as either a wchar or char (no need to change settings then), depending on your compiler settings.
|
|
| Back to top |
|
 |
|