Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Noob Question]WIN32 API Compiling error.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sotaukko
Cheater
Reputation: 0

Joined: 23 Oct 2007
Posts: 32

PostPosted: Tue Oct 21, 2008 11:27 am    Post subject: [Noob Question]WIN32 API Compiling error. Reply with quote

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
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Oct 21, 2008 11:51 am    Post subject: Reply with quote

Use either unicode strings or compile in ANSI.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Oct 21, 2008 11:54 am    Post subject: Reply with quote

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
View user's profile Send private message
sotaukko
Cheater
Reputation: 0

Joined: 23 Oct 2007
Posts: 32

PostPosted: Tue Oct 21, 2008 12:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Tue Oct 21, 2008 12:18 pm    Post subject: Reply with quote

Visual Studio options are a total pain in the ass. Try googling "Visual C++ ansi" or wait for someone to tell you Very Happy.
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Tue Oct 21, 2008 1:07 pm    Post subject: Reply with quote

Code:
MessageBoxA(NULL, "Goodbye", "Note", MB_OK);

or
Code:
#include <tchar.h>

MessageBox(NULL, _T("Goodbye"), _T("Note"), MB_OK);
Back to top
View user's profile Send private message
SFP+
Comp. talk moderator
Reputation: 26

Joined: 02 May 2007
Posts: 1228
Location: Sweden

PostPosted: Tue Oct 21, 2008 1:44 pm    Post subject: Reply with quote

Back to top
View user's profile Send private message
smartz993
I post too much
Reputation: 2

Joined: 20 Jun 2006
Posts: 2013
Location: USA

PostPosted: Tue Oct 21, 2008 2:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites