Menu

GDI+

2007-06-16
2012-09-26
  • Nobody/Anonymous

    These are the steps to access GDI+ from Dev-C++/MingGW. Not sure if this is still an issue for anyone, but googling it yesterday it seems a lot of people thought it was an impossible task. It isn't.

    Download "Microsoft Platform SDK for Windows Server 2003 R2" from Microsoft (no charge). You only need this for the include files.

    Create a new directory - call it anything you want, say C:\gdiplus_inc. Copy only the gdiplus*.h files to this directory:

    C:\gdiplus_inc>copy \program files\Microsoft Platform SDK for Windows Server 2003 R2\include\gdiplus*

    Add c:\gdiplus_inc to your include directories in your dev-c++ project or make file. You don't want to include from the microsoft directory because it will pick up all its nonstandard header files instead of the dev-c++ versions. (And I think the eight-word subdirectory could cause problems, too.)

    The gdiplus*.h headers are OK for the most part, but you do need to make the following changes:


    GdiplusEnums.h:

    remove the following line:
    'enum EmfPlusRecordType;'

    change
    '#define GDIP_WMF_RECORD_TO_EMFPLUS(n) ((EmfPlusRecordType)((n) | GDIP_WMF_RECORD_BASE))'

    to this:
    '#define GDIP_WMF_RECORD_TO_EMFPLUS(n) (((n) | GDIP_WMF_RECORD_BASE))'


    GdiplusImaging.h:

    change
    'PixelFormat PixelFormat;'

    to:
    'PixelFormat PFormat;'

    This is only a stopgap to get it to compile. However there's no problem if you aren't already using source code that accesses it. (Its a public member of some struct). If you are, then you need a more permenant solution. The problem is Microsoft has given a variable the same name as a typedef. (Cute, huh?)


    GdiplusHeaders.h:

    change:
    'friend Graphics;'

    to:
    'friend class Graphics'


    That's it. Now your code will compile.

    To link, you will need to create an import lib - libgdiplus.a

    First, create a def file:

    pexports gdiplus.dll > gdiplus.def

    When I ran pexports it crashed for some reason before completing. The def file is just

    LIBRARY gdiplus.dll
    EXPORTS

    followed by the list of exports, e.g.:

    LIBRARY gdiplus.dll
    EXPORTS
    GdipAddPathArc
    GdipAddPathArcI
    GdipAddPathBezier
    GdipAddPathBezierI
    .
    .
    .

    You can get the export names by running 'pedump gdiplus.dll' and then copying them to your def file.

    Now you will create an import lib from the def file:

    dlltool -d gdiplus.def -l libgdiplus.a -k

    Now you just specify this lib in your make file (where all the other lib*.a files are), or wherever it goes in your dev-c++ project.

    You can start coding now with GDI+, but here's the caveat: Whenever you use a GDI+ function for the first time, you will get a linker error, e.g. 'Could not find GdipCloneBrush@8.' All you need to do is find GdipCloneBrush in your def file, append @8 (or @4 or whatever) to the end of it, save it, run dlltool again, recompile, and your project will link and run.

     
    • Nobody/Anonymous

      And don't forget

      'using namespace Gdiplus;'

       
    • Nobody/Anonymous

      minor typo (forgot the semicolon):

      GdiplusHeaders.h:

      change:
      'friend Graphics;'

      to:
      'friend class Graphics;'

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.