Thread View: borland.public.cppbuilder.nativeapi
11 messages
11 total messages
Started by 4N
Thu, 05 Jul 2007 17:47
how to resolve conflicts in gdi+ ?
Author: 4N
Date: Thu, 05 Jul 2007 17:47
Date: Thu, 05 Jul 2007 17:47
13 lines
1390 bytes
1390 bytes
Hi, I've integrated gdi+ in a project, but I have a problem with the header files: the compiler can't choose the correct constructor for the Gdiplus::Graphics class (to be precise I use the following command "Gdiplus::Graphics graphics(hdc);" ). I can solve it declaring STRICT as parameter in the global definitions but this leads to a load of casts in my other functions. I'd like to avoid to modify all my calls so the question is... is there a different solution? Thanks.
Re: how to resolve conflicts in gdi+ ?
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Jul 2007 17:49
Date: Thu, 05 Jul 2007 17:49
20 lines
1519 bytes
1519 bytes
"4N" <xxxx@yyyy.zzz> wrote in message news:468d2ea0@newsgroups.borland.com... > I've integrated gdi+ in a project, but I have a problem with the > header files: the compiler can't choose the correct constructor > for the Gdiplus::Graphics class (to be precise I use the following > command "Gdiplus::Graphics graphics(hdc);" ). I use that same statement in my GDI+ code and it works fine for me. > I can solve it declaring STRICT as parameter in the global definitions but > this leads to a load of casts in my other functions. Then those calls were probably wrong to begin with. Can you provide an example of what is not working anymore? Gambit
Re: how to resolve conflicts in gdi+ ?
Author: 4N
Date: Thu, 05 Jul 2007 18:45
Date: Thu, 05 Jul 2007 18:45
44 lines
2304 bytes
2304 bytes
oops, maybe I should have used the "graphics" group, sorry.
> I use that same statement in my GDI+ code and it works fine for me.
How? If I don't define STRICT the code stops in the last line of the
following code (inside the file GDIPLUSGRAPHICS.H):
class Graphics : public GdiplusBase
{
public:
friend class Region;
friend class GraphicsPath;
friend class Image;
friend class Bitmap;
friend class Metafile;
friend class Font;
friend class FontFamily;
friend class FontCollection;
friend class CachedBitmap;
static Graphics* FromHDC(IN HDC hdc)
{
return new Graphics(hdc);
and I get the errors:
[C++ Error] GdiplusGraphics.h(34): E2015 Ambiguity between
'Gdiplus::Graphics::Graphics(void *)' and 'Gdiplus::Graphics::Graphics(void
*,int)'
[C++ Error] OpenImages.cpp(294): E2015 Ambiguity between
'Gdiplus::Graphics::Graphics(void *)' and 'Gdiplus::Graphics::Graphics(void
*,int)'
If I define STRICT there are functions that need cast, eg. an error I get
is:
const HANDLE handle=...;
GetWindowLong(handle, GWL_STYLE);
[C++ Error] Unit_Main.cpp(3297): E2034 Cannot convert 'void * const' to
'HWND__ *'
[C++ Error] Unit_Main.cpp(3297): E2342 Type mismatch in parameter 'hWnd'
(wanted 'HWND__ *', got 'void *')
Re: how to resolve conflicts in gdi+ ?
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Jul 2007 19:10
Date: Thu, 05 Jul 2007 19:10
44 lines
2619 bytes
2619 bytes
"4N" <xxxx@yyyy.zzz> wrote in message news:468d3c18@newsgroups.borland.com... > How? I don't use STRICT in my code and it works fine. I don't do anything special for it. > If I don't define STRICT the code stops in the last line > of the following code (inside the file GDIPLUSGRAPHICS.H): Then the compiler is wrong. There is no ambiquity in that code. The Graphics class has only two constructors which accept an HDC as a parameter. The first constructor accepts only an HDC by itself, whereas the second constructor accepts an additional HANDLE parameter. That parameter does not have a default value defined, however, so there is no way that passing an HDC by itself to a Graphics constructor like FromHDC(HDC) does can be ambiquious with the second constructor. It doesn't matter if STRICT is defined or not. The number of parameters dictates which constructor to call before the parameter types are then validated. > If I define STRICT there are functions that need cast, eg. an > error I get is: > > const HANDLE handle=...; > GetWindowLong(handle, GWL_STYLE); > > [C++ Error] Unit_Main.cpp(3297): E2034 Cannot convert 'void * const' > to 'HWND__ *' The error is correct in this case. Your code is simply wrong to begin with. GetWindowLong() expects an HWND, not a HANDLE. The two are not the same thing, especially more so when STRICT is defined. This is exactly the type of thing that STRICT was designed for - it forces you to use proper coding so that you can catch such errors. When STRICT is not defined, HANDLE and HWND are both void* and thus are interchangable in code, but that is not necessarily the right thing to do logically. Gambit
Re: how to resolve conflicts in gdi+ ?
Author: 4N
Date: Thu, 05 Jul 2007 19:40
Date: Thu, 05 Jul 2007 19:40
17 lines
1872 bytes
1872 bytes
> Then the compiler is wrong. There is no ambiquity in that code. The > Graphics class has only two constructors which accept an HDC as a > parameter. The first constructor accepts only an HDC by itself, > whereas the second constructor accepts an additional HANDLE parameter. > That parameter does not have a default value defined, however, so > there is no way that passing an HDC by itself to a Graphics > constructor like FromHDC(HDC) does can be ambiquious with the second > constructor. It doesn't matter if STRICT is defined or not. The > number of parameters dictates which constructor to call before the > parameter types are then validated. the compiler is wrong obviously, but the point is: what can I do to make it work properly ? Have I to assume there's no solution (for you at least) since you didn't point me any? Anyway thanks again for the time you spent replying to me.
Re: how to resolve conflicts in gdi+ ?
Author: Darko Miletic
Date: Thu, 05 Jul 2007 20:31
Date: Thu, 05 Jul 2007 20:31
19 lines
1631 bytes
1631 bytes
4N wrote: > oops, maybe I should have used the "graphics" group, sorry. > > > If I define STRICT there are functions that need cast, eg. an error I get > is: > > const HANDLE handle=...; > GetWindowLong(handle, GWL_STYLE); As Remy told you GetWindowLong expects HWND and not const HANDLE (const void*). Dirty hack would be something like this: GetWindowLong(reinterpret_cast<HWND>(const_cast<HANDLE>(handle)),GWL_STYLE); I just do not understand why are you using HANDLE in the first place instead of HWND.
Re: how to resolve conflicts in gdi+ ?
Author: Bob Gonder
Date: Thu, 05 Jul 2007 20:55
Date: Thu, 05 Jul 2007 20:55
17 lines
2003 bytes
2003 bytes
Remy Lebeau (TeamB) wrote: >Then the compiler is wrong. There is no ambiquity in that code. The >Graphics class has only two constructors which accept an HDC as a >parameter. The first constructor accepts only an HDC by itself, >whereas the second constructor accepts an additional HANDLE parameter. >That parameter does not have a default value defined, however, so >there is no way that passing an HDC by itself to a Graphics >constructor like FromHDC(HDC) does can be ambiquious with the second >constructor. It doesn't matter if STRICT is defined or not. The >number of parameters dictates which constructor to call before the >parameter types are then validated. From my C perspective, those constructors are forward references (FromHDC(HDC) occurs before the HDC constructor is described). It seems to me that the compiler might make assumptions about a default constructor, but be unable to reconcile 2 different constructors that it doesn't know about.
Re: how to resolve conflicts in gdi+ ?
Author: Alan Bellingham
Date: Thu, 05 Jul 2007 21:55
Date: Thu, 05 Jul 2007 21:55
17 lines
1526 bytes
1526 bytes
Darko Miletic <kiklop@fibertel.com.ar> wrote: >> const HANDLE handle=...; >> GetWindowLong(handle, GWL_STYLE); >GetWindowLong(reinterpret_cast<HWND>(const_cast<HANDLE>(handle)),GWL_STYLE); Why the const_cast<>? It should be totally irrelevant, since it's a top level const in this case, and GetWindowLong receives its first parameter by value, not by reference. Alan Bellingham -- Team Browns <url:http://www.borland.com/newsgroups/> Borland newsgroup descriptions <url:http://www.borland.com/newsgroups/netiquette.html> netiquette
Re: how to resolve conflicts in gdi+ ?
Author: 4N
Date: Thu, 05 Jul 2007 22:15
Date: Thu, 05 Jul 2007 22:15
5 lines
1154 bytes
1154 bytes
> I just do not understand why are you using HANDLE in the first place > instead of HWND. because the value I assign to the variable is a HANDLE, anyway the point isn't that, that was just an example.
Re: how to resolve conflicts in gdi+ ?
Author: Remy Lebeau (TeamB)
Date: Fri, 06 Jul 2007 01:17
Date: Fri, 06 Jul 2007 01:17
15 lines
1366 bytes
1366 bytes
"4N" <xxxx@yyyy.zzz> wrote in message news:468d6d7e$1@newsgroups.borland.com... > because the value I assign to the variable is a HANDLE Then it probably isn't a real HWND to begin with. > anyway the point isn't that, that was just an example. Then it was a bad example. You really do need to make sure that you are always using proper data types in all operations. Gambit
Re: how to resolve conflicts in gdi+ ?
Author: 4N
Date: Fri, 06 Jul 2007 07:24
Date: Fri, 06 Jul 2007 07:24
9 lines
1545 bytes
1545 bytes
> Then it was a bad example. You really do need to make sure that you > are always using proper data types in all operations. yeah, ok, my mistake. Anyway I corrected all the calls and now I can use the gdi+ using STRICT as global define, but I wonder why it happens. It's a known issue anyway as I could read here: http://www.leunen.com/cbuilder/gdiplus.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads