-
December 7th, 2011, 06:30 PM
#1
GDI+ and Flat API
I am trying to figure out how to call a GDI+ Flat Api function, but cannot get anything working.
Here is my code:
Code:
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include <GdiplusFlat.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
VOID OnPaint(HDC hdc)
{
Graphics graphics(hdc);
Pen pen(Color(255, 0, 0, 255));
//graphics.DrawLine(&pen, 0, 0, 200, 100);
GdipDrawLine(&graphics, &pen, 0, 0, 200, 0); //Flat Api version
}
Here I am trying to call only one flat function GdipDrawLine.
Any suggestions?
Last edited by mmscg; December 8th, 2011 at 11:08 PM.
-
December 8th, 2011, 06:02 AM
#2
Re: GDI+ and Fat API
- Once included Gdiplus, use DllExports namespace i.e. DllExports::GdipDrawLine.
- First two arguments of DllExports::GdipDrawLine are not of type Gdilpus::Graphics and Gdiplus::Pen, but GpGraphics and GpPen.
Code:
GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1, REAL y1,
REAL x2, REAL y2);
None has implicit conversion from one to another. - It has no sense in a C++ program to directly use flat GDI+ APIs.
Generally, GDI+ classes methods are simple inline wrappers, e.g.
Code:
Status DrawLine(IN const Pen* pen,
IN INT x1,
IN INT y1,
IN INT x2,
IN INT y2)
{
return SetStatus(DllExports::GdipDrawLineI(nativeGraphics,
pen->nativePen,
x1,
y1,
x2,
y2));
}
- Given the above points, you have to choose one of two:
- Use only GDI+ classes, recommended in C++ code;
- Use GDI+ flat API only in C code (as well as in other languages, except C++).
Last edited by ovidiucucu; December 8th, 2011 at 06:04 AM.
-
December 8th, 2011, 11:16 PM
#3
Re: GDI+ and Flat API
So are you are saying the Flat Api functions cannot be used in C++,
or just that using the wrapper method is easier?
I added
using namespace Gdiplus:: DllExports;
to my code and I now get this error:
error C2664: 'Gdiplus:llExports::GdipDrawLine' : cannot convert parameter 1 from 'Gdiplus::Graphics *__w64 ' to 'Gdiplus::GpGraphics *'
-
December 9th, 2011, 05:33 AM
#4
Re: GDI+ and Flat API
Originally Posted by mmscg
So are you are saying the Flat Api functions cannot be used in C++,
or just that using the wrapper method is easier?
I have never said "cannot". You can use flat GDI+ API in C++ code but it's like scratching with the foot.
Yes, the (wrapper) C++ classes are easier to use in C++ code. For that purpose they have been designed.
Originally Posted by mmscg
I added
using namespace Gdiplus:: DllExports;
to my code and I now get this error:
error C2664: 'Gdiplus: llExports::GdipDrawLine' : cannot convert parameter 1 from 'Gdiplus::Graphics *__w64 ' to 'Gdiplus::GpGraphics *'
Have you ever read this?
Originally Posted by ME
- First two arguments of DllExports::GdipDrawLine are not of type Gdilpus::Graphics and Gdiplus::Pen, but GpGraphics and GpPen.
Code:
GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1, REAL y1,
REAL x2, REAL y2);
None has implicit conversion from one to another.
...
-
December 9th, 2011, 10:12 AM
#5
Re: GDI+ and Fat API
Yes, I had read that, but still being fairly new to C++ I find this very confusing.
Can one type be cast to another then?
I have been using GDI+ in my VB6 projects for the last year, and have become fairly proficient with the Flat Apis.
As I continue to learn C++, and start to port some of my projects from VB6 to C++,
I thought it might be easier for me to continue to use the Flat Api methodology for the GDI+ conversion.
Also now, even for just curiosity sake, I would like to see how to draw a line in C++ using flat GDI+ api.
-
December 10th, 2011, 01:10 AM
#6
Re: GDI+ and Fat API
Well, here is an example of using GDI+ flat API.
Code:
using namespace DllExports;
GpPen* pen = NULL;
GpGraphics* graphics = NULL;
ARGB color = 255 << ALPHA_SHIFT | 255 << BLUE_SHIFT;
GpUnit unit = UnitPixel;
REAL width = 1.0;
GdipCreatePen1(color, width, unit, &pen);
GdipCreateFromHDC(hdc, &graphics);
GdipDrawLine(graphics, pen, 0, 0, 100, 50);
// ...
GdipDeletePen(pen);
GdipDeleteGraphics(graphics);
Resources
Last edited by ovidiucucu; December 10th, 2011 at 01:14 AM.
-
December 10th, 2011, 05:01 PM
#7
Re: GDI+ and Flat API
Thank you... you C++ guys are amazing!!
This works perfectly for me, and should be enough to get me on my way.
(I'm sure I'll hit a few stumbling blocks, and might have to ask more questions).
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
|