-
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
-
What does GetPen return? You should just be able to use a C-style cast "(HPEN)(a_void*_pointer)".
-
sorry...
i pressed the wrong button, so i answered to you in another thread :) it is named "here..."
-
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
-
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.
-
so..
Code:
p = x; /* only ok in C, C++ needs (int*)x */
this line converts x to an int*, right?
Thanks
Amon Ra
-
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.