|
-
Jun 30th, 2001, 05:57 PM
#1
Thread Starter
Hyperactive Member
SelectObject
Code:
HPEN pen_use; //pen to use
HPEN pen_old;
pen_use = GetPen(1,GetSysColor(COLOR_BTNSHADOW));
pen_old = SelectObject(m_hDC, pen_use);
SelectObject(m_hDC, pen_old);
DeleteObject(pen_use);
O, GetPen is a function I wrote, it works fine. But what I don't understand, is that it gives me this error when i compile:
Code:
error C2440: '=' : cannot convert from 'void' to 'struct HPEN__ *'
Expressions of type void cannot be converted to other types
I went on msdn and they even have an example doing the same thing, and they shay it shyould workd. Help? Thanks
Amon Ra
Amon Ra
The Power of Learning.
-
Jun 30th, 2001, 06:40 PM
#2
Monday Morning Lunatic
What does GetPen return? You should just be able to use a C-style cast "(HPEN)(a_void*_pointer)".
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 30th, 2001, 07:13 PM
#3
Thread Starter
Hyperactive Member
sorry...
i pressed the wrong button, so i answered to you in another thread it is named "here..."
Amon Ra
The Power of Learning.
-
Jun 30th, 2001, 08:02 PM
#4
Thread Starter
Hyperactive Member
Thanks again Parksie So, is it possible to do a cast everytime there is a void? Because, if it is void, it does not return anything, right. So how can you convert nothing to an HPEN?
Amon Ra
Amon Ra
The Power of Learning.
-
Jun 30th, 2001, 08:10 PM
#5
Monday Morning Lunatic
void is nothing, and can't be casted. void* is different - it's a generic pointer, and so could be anything. C allows you to do this:
Code:
int *p;
void *x;
int a;
p = &a; /* ok in C and C++ */
x = p; /* ok in C and C++ */
p = x; /* only ok in C, C++ needs (int*)x */
The reason you can cast to HPEN is because you provided an HPEN, and by design SelectObject returns the same type of GDI object, even though technically it's the same type. However, since you know better, you can override the compiler and cast it.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 30th, 2001, 08:38 PM
#6
Thread Starter
Hyperactive Member
so..
Code:
p = x; /* only ok in C, C++ needs (int*)x */
this line converts x to an int*, right?
Thanks
Amon Ra
Amon Ra
The Power of Learning.
-
Jun 30th, 2001, 08:46 PM
#7
Monday Morning Lunatic
C will automatically convert the pointer, but in C++ this violates the basic type safety rules, and as such is forbidden by the compiler without a cast.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|