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 


[C++] HFONT issue
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Jul 20, 2008 10:54 pm    Post subject: [C++] HFONT issue Reply with quote

I'm following theForger's Win32API tutorial, attempting to make a basic text editor.

As you can see hfDefault has been assigned as type HFONT.
Code:
 HFONT hfDefault;


However, when I compile it, I receive an error on this line:
Code:
hfDefault = GetStockObject(DEFAULT_GUI_FONT);


The error is: The error I receive is: invalid conversion from `void*' to `HFONT__*'



This is the part of the code where the error arises:
Code:
case WM_CREATE:
{
HFONT hfDefault;
HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE |
ES_AUTOVSCROLL | ES_AUTOHSCROLL,
0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL),
NULL);
if(hEdit == NULL)
MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK |
MB_ICONERROR);

hfDefault = GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
}
break;

_________________
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sun Jul 20, 2008 11:08 pm    Post subject: Reply with quote

Have you even tried type casting? o.o
Code:
hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 20, 2008 11:10 pm    Post subject: Reply with quote

If you look at the GetStockObject documentation, it shows that the API returns an HGDIOBJ type.

Quote:

HGDIOBJ GetStockObject(
int fnObject // stock object type
);


So typecast it so that it returns an HFONT.

Code:

HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);


EDIT:

Beaten to it by Symbol.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Jul 20, 2008 11:27 pm    Post subject: Reply with quote

Using the line provided by Symbol I get weird linker errors:

Quote:
In function `Z7WndProcP6HWND__jjl':
[Linker error] undefined reference to `GetStockObject@4
ld returned 1 exit status





Using the line provided by oib111 I get multiple declaration errors:

Quote:
redeclaration of `HFONT__*hfDefault'
`HFONT__*hfDefault' previously declared here



_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 20, 2008 11:31 pm    Post subject: Reply with quote

Go download VC++. Dev-C++ is horrible; only should be used as a backup.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Jul 20, 2008 11:35 pm    Post subject: Reply with quote

lol, I have Microsoft Visual Studios 2008, like, the whole goddam thing. But I never know what kind of file to open. As in File->New->(What the fuck do i do now, theres like 50 options). Confused
_________________
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Sun Jul 20, 2008 11:36 pm    Post subject: Reply with quote

Win32 Console or any other Win32 project.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 20, 2008 11:37 pm    Post subject: Reply with quote

Open up VC++. Hit Ctrl+Shift+N. Go to Win32 and choose Win32 Project. Name it, click next, next, fill in options, finish.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Sun Jul 20, 2008 11:40 pm    Post subject: Reply with quote

Code:
HFONT hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);


Put that line above your function, so that it becomes a global.
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Jul 20, 2008 11:49 pm    Post subject: Reply with quote

Hmm Thanks, I think I've got the hang of it. + Whats the hotkey to compile?
_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 20, 2008 11:50 pm    Post subject: Reply with quote

F5.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Jul 20, 2008 11:52 pm    Post subject: Reply with quote

Omg. DevC++ returned 3 lines of errors. Look at what VC++ returns

Quote:
Compiling...
VCSOUrce.cpp
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(1Cool : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(21) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [27]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(6Cool : error C2440: '=' : cannot convert from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(73) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\hp_owner.matmo.000\desktop\testingvc\testingvc\vcsource.cpp(87) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Christ...

@Zand, tried it. More linker errors.

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sun Jul 20, 2008 11:54 pm    Post subject: Reply with quote

It's because your coding with MBCS (multi-byte character set) and the default character set for VC++ is Unicode. Go to View>Property Pages, and go to Configuration Properties>General>Character Set>Multi-byte Character set
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Mon Jul 21, 2008 12:00 am    Post subject: Reply with quote

Thanks oib! LIFESAVER! (Its working now Wink )
_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Mon Jul 21, 2008 12:10 am    Post subject: Reply with quote

No problem.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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