The MASM Forum Archive 2004 to 2012

Project Support Forums => GoAsm Assembler and Tools => Topic started by: donkey on February 12, 2010, 09:09:51 AM

Title: GDI+ scribble
Post by: donkey on February 12, 2010, 09:09:51 AM
I am testing the capabilities of GDI+ this week and wrote a small drawing program using it. The main thing to note with GDI+ is the separation of the vector drawing and image manipulation functions into 2 groups, Graphics and Image. This leads to a few inconsistencies with the way things were done in the GDI, mainly the complete lack of vector drawing functions for bitmaps, LineTo and Poly's are history except when dealing with Graphics objects as well as all of the familiar Pen and Brush functions. So, in order to have the best of both worlds you have write your own. For my test I adapted my bresenham line function so it works with GDI+ directly and incorporated it into a little test package called Scribble. It is named after a similar one for the GDI I saw on this board many years ago (I think Bcraven wrote it) but is now lost. To build this project you will have to locate GDIplus.DLL version 1.1 and Comctl32.dll version 6 and copy them into the project folder. The exe and source are included.

Scribble uses the GdipBitmapLockBits function to obtain a pointer to the bitmap data in a way similar to how GetObject works with the GDI. It then manipulates the memory directly either by setting a single pixel or drawing a line. There are many functions that I included that are not used in the demo but the code is there none the less.

Have fun

Edgar
Title: Re: GDI+ scribble
Post by: ecube on February 12, 2010, 09:55:43 AM
"This Application has failed to start because the application configuration is incorrect.Reinstalling the application may fix the problem".
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 10:01:09 AM
Quote from: E^cube on February 12, 2010, 09:55:43 AM
"This Application has failed to start because the application configuration is incorrect.Reinstalling the application may fix the problem".

Mmmm, not sure what the problem could be. What OS are you running it on Win7 ?
Title: Re: GDI+ scribble
Post by: ecube on February 12, 2010, 10:01:59 AM
XP Sp2, stock I believe. I tried copying the manifest into the same directory and it didn't help so idk either.
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 10:04:51 AM
Quote from: E^cube on February 12, 2010, 10:01:59 AM
XP Sp2, stock I believe. I tried copying the manifest into the same directory and it didn't help so idk either.

The manifest is in the resource section of the executable. Have to try it on XP tomorrow, perhaps you don't have GDI+ 1.1 available, have you looked in the WinSxS folder to see if it was there ?
Title: Re: GDI+ scribble
Post by: dedndave on February 12, 2010, 10:20:56 AM
same here, Edgar - xp pro sp2
i do have gdi+ 5.1.3097.0 and 5.1.3102.2180
Title: Re: GDI+ scribble
Post by: dedndave on February 12, 2010, 10:34:28 AM
http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/36971526-95f3-4a9f-a601-1843c86332c1
Title: Re: GDI+ scribble
Post by: dedndave on February 12, 2010, 10:42:35 AM
i noticed when i install newer versions of yahoo messenger, it runs vcredist_x86.exe
it's the first thing that it does, too
Title: Re: GDI+ scribble
Post by: sinsi on February 12, 2010, 10:51:35 AM
Win7 x64 RC works well, no flickers or artifacts.
Title: Re: GDI+ scribble
Post by: Bill Cravener on February 12, 2010, 01:51:19 PM
Works ok with Vista sp2.
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 03:41:00 PM
Hi Dave and E^Cube,

GDI+ versioning is a bit weird, 5.1.3097.0 and 5.1.3102.2180 are both versions 1.0. GDI+ Version 1.1 has a DLL version 6.0 or greater. I mentioned this in the following thread:

http://www.masm32.com/board/index.php?topic=13348.0

I was going to include it with the app but its a little demo and a 2 MB DLL was a bit much to pack up with it so I put in a res based manifest and who ever has it has it...

This version will run with GDI+ version 1.0, though all of the effects and file ops that I included as extra functions have to be commented out:

Edgar
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 04:34:17 PM
As a side note, Yuri's idea about API versioning made making the application GDI+ 1.0 compatible very easy, it will be a really good addition to the header project and will be uploaded as part of the main project later today. When I changed the Windows version to NTDDI_WINXP from NTDDI_VISTA and set the FILTERAPI switch I got the following message:

QuoteGoLink.Exe Version 0.26.10 - Copyright Jeremy Gordon 2002/9 - JG@JGnet.co.uk

Error!
The following symbols were not defined in the object file or files:-
GdipInitializePalette_NotAvailable
GdipBitmapConvertFormat_NotAvailable
GdipBitmapApplyEffect_NotAvailable
Output file not made

Awesome addition that should make writing for different versions of Windows a much easier task. Yuri has earned a mention in the Windows.h file for that one  :bg

Edgar
Title: Re: GDI+ scribble
Post by: Yuri on February 12, 2010, 07:03:23 PM
Quote from: donkey on February 12, 2010, 04:34:17 PM
Yuri has earned a mention in the Windows.h file for that one :bg

Thanks for the honour. :bg My role was very small, since both the idea and the work are actually yours. In the meanwhile I encountered the same issue, now it was my DLL which failed to get loaded under XP.
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 08:03:08 PM
Hi Yuri,

Dependency Walker (http://support.microsoft.com/kb/256872) is a great utility to search for things like that, I use it a lot when I get mysterious failures like that.
Title: Re: GDI+ scribble
Post by: BlackVortex on February 12, 2010, 08:04:54 PM
I found a gdiplus.dll versioned 6.1.xxx and put it on my XP installation in the same folder, but still same error.

Works fine on win7x64 of course. I'm talking about the link in the first post.

How can I tell the windows loader to use that dll ? Do I have to register something, somehow ?
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 08:13:48 PM
Quote from: BlackVortex on February 12, 2010, 08:04:54 PM
I found a gdiplus.dll versioned 6.1.xxx and put it on my XP installation in the same folder, but still same error.

Works fine on win7x64 of course. I'm talking about the link in the first post.

How can I tell the windows loader to use that dll ? Do I have to register something, somehow ?

Hi,

That is a limitation in manifest files as described here, please read through the article, it will help you solve most manifest and SxS issues:

http://www.masm32.com/board/index.php?topic=13348.0

You would require a different manifest for it, you can always alter the manifest to include <file name = "gdiplus.dll"/> and recompile the rc and assembler the project to make it work if you like. This was a just a small test of GDI+, I knew about the issues in versioning which is why the original has WINVER set to VISTA and not the default XP, I should really have mentioned that it was only sporadically compatible with XP in the original post, sorry.
Title: Re: GDI+ scribble
Post by: BlackVortex on February 12, 2010, 08:19:58 PM
Your current manifest is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
      <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="GdipScribble" type="win32"/>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
            <security>
                  <requestedPrivileges>
                        <requestedExecutionLevel level="asInvoker" />
                  </requestedPrivileges>
            </security>
      </trustInfo>
      <dependency>
          <dependentAssembly>
              <assemblyIdentity
                  type="win32"
                  name="Microsoft.Windows.Common-Controls"
                  version="6.0.0.0"
                  language="*"
                  processorArchitecture="x86"
                  publicKeyToken="6595b64144ccf1df"
              />
          </dependentAssembly>
      </dependency>
      <dependency>
          <dependentAssembly>
              <assemblyIdentity
                  type="win32"
                  name="microsoft.windows.gdiplus"
                  version="1.1.0.0"
                  language="*"
                  processorArchitecture="x86"
                  publicKeyToken="6595b64144ccf1df"
              />
          </dependentAssembly>
      </dependency>
</assembly>

What would be the correct one ?
Title: Re: GDI+ scribble
Post by: donkey on February 12, 2010, 08:29:22 PM
Hi BlackVortex,

Leaving the GDI+ dependency will force the loader to look only in the SxS folder for a version of the DLL that meets your needs. If you want to use a DLL in your app folder you have to change the manifest as detailed here:

http://www.masm32.com/board/index.php?topic=13348.0

If you read the last section:

QuoteNow, what if you want to ensure that your version of the DLL is exactly the one used ? Well, if its redistributable no problem, you have simply to include it with your distribution. But you ask, won't Windows go looking for the highest version above my requirements and use that instead ? Yes, it will, so we need to use a different manifest if we are distributing the DLL in our application folder, in this case we'll assume that we have shipped GDIPLUS.DLL with the application and we need that particular one:

The example manifest that follows will work for you in this case (change the program name). Then recompile the RC file and reassemble the project and it should work fine.

Edgar
Title: Re: GDI+ scribble
Post by: Yuri on February 12, 2010, 08:52:22 PM
Quote from: donkey on February 12, 2010, 08:03:08 PM
Hi Yuri,

Dependency Walker (http://support.microsoft.com/kb/256872) is a great utility to search for things like that, I use it a lot when I get mysterious failures like that.

Thanks, in fact I already have it installed but have completely forgotten about that.  :toothy
Title: Re: GDI+ scribble
Post by: BlackVortex on February 12, 2010, 08:56:10 PM
Arrgh, still couldn't get it to work on XP. But I was bored to recompile it and I just resource hacked the new manifest in it. It works on win7, but gave a side-by-side... error on XP as before. Anyway, I was just fooling around.
If I resource-hack-delete the manifest resource, then I get a GdipInitialize..blahblah... procedure entry missing on my XP installation. Maybe the gdiplus.dll I fished from my win7 installation sucks ? It's version 6.1 and weighs in at 1.54mb

By the way, PeCompact can compress gdiplus.dll to 663kb and UPX to 656kb ! 41% of original, not bad.  :green
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 12:03:25 AM
Try this, this is the last I am tackling with this problem, the app is Vista and above though this should work on XP. You need to copy gdiplus.dll version 1.1 (dll version 6.0 or greater) into the application folder.
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 01:20:16 AM
An interesting thing, I was just trying was to see if there was a faster way to lock the bits and it seems that GdipBitmapLockBits accepts NULL for the region so there is no need to pass the RECT if you just want to lock the entire bitmap...

invoke GdipBitmapLockBits,[pPic],NULL,ImageLockModeWrite,PixelFormat32bppARGB,offset bmd

This is undocumented behavior however.

Edgar
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 01:38:32 AM
There seems to be a problem when editing zoomed images, there is an artifact in the image that survives even when it is saved so it is not a problem with the zooming process but with garbage being written to the buffer returned by GdipBitmapLockBits. I can't figure out what is wrong though, this image was zoomed 4x then edited, only one pixel was drawn (a red one) then saved...

(http://img693.imageshack.us/img693/2826/testpic.png)

Edgar
Title: Re: GDI+ scribble
Post by: ecube on February 13, 2010, 04:51:32 AM
I can't even find gdiplus 6.* anywhere(besides massive SDK), I only have 5.13 and it complains about gdiinitzliepalette not existing. anyway I give up
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 04:54:13 AM
Cube - i think it depends on which OS you have
i am using xp pro and have version 5's also
6 seems to be a vista and/or win7 thing
i don't think you can just transplant GdiP 6 into xp   :bg
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 05:09:23 AM
Quote from: dedndave on February 13, 2010, 04:54:13 AM
Cube - i think it depends on which OS you have
i am using xp pro and have version 5's also
6 seems to be a vista and/or win7 thing
i don't think you can just transplant GdiP 6 into xp   :bg

Though GDI+ version 1.1 is redistributable down to Win98 you should never replace the version in \System32. If it has not been installed in the Side by Side folder then you have to include it in the application folder and include a special manifest. Both Windows Vista and Win7 have version 1.0 in System32 though they have 1.1 as a side by side in all versions. For example my laptop (which I'm on right now), is a Vista box with version 5.2.6002.18005 in System32.

about 900K

<File removed, you can get it from the power point viewer here (http://www.masm32.com/board/index.php?topic=13366.msg104278#msg104278)>

Get it fast I am not hosting this file forever...

Edgar
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 05:37:13 AM
thanks much, Edgar
now, let me figure out the right way to install it   :P
Title: Re: GDI+ scribble
Post by: ecube on February 13, 2010, 05:43:51 AM
now it says "the procedure entry point _except_handler4_common could not be located in the dynamic link library msvcrt.dll"

lol...i'll just test in win7 in vmware
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 05:45:21 AM
it appears i need the CAT file, the manifest file in WinSxs, and some registry entries
i don't suppose there is an INF file someplace
there has to be a right way to do this - lol
i wonder if updating DirectX would update GdiPlus
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 05:52:27 AM
this may be it
http://support.microsoft.com/KB/958911

KB958911 for XP
http://www.microsoft.com/downloads/details.aspx?FamilyId=3296f213-4c70-4616-8375-7d20af9843c5&displaylang=en

well - that got me version 5.2.6001.22290

that tells me there may be a newer ms KB to get the job done   :8)
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 06:00:29 AM
KB975337 gets you 5.2.6001.22319 - a security update
Title: Re: GDI+ scribble
Post by: dedndave on February 13, 2010, 06:13:21 AM
this page tells you all the gdi versions for different versions of windows
http://support.microsoft.com/kb/956802

then, from that "w" site....

QuoteIn Windows Vista, all Windows applications including GDI and GDI+ applications run in the new compositing engine, Desktop Window Manager which is built atop the Windows Display Driver Model. The GDI render path is redirected through DWM and GDI is no longer hardware-accelerated by video card driver. However, due to the nature of desktop composition (internal management of moving bitmaps and transparency and anti-aliasing of GDI+ being handled at the DWM core), operations like window moves can be faster or more responsive because underlying content does not need to be re-rendered by the application.

the conclusion i am drawing is that it may not work if i did get it installed - lol
but, i would need the registry entries, cat and manifest files to install it correctly

i may play with it tomorrow
maybe i will roll my own install files   :bg

EDIT - Edgar - maybe you could export the registry entries for that version from:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Installations]
and post that exported reg file and the CAT file from WinSxS
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 06:33:13 AM
Well, it seems that GDI+ 1.1 is not redistributable, you will need either Win7/Vista or install Office 2003 in order to get it. Oh well, XP users are out in the cold.

Microsoft Communities (http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.platformsdk.gdi&tid=9fd5c32d-07c6-4777-833c-6b47e1273b95&cat=en_us_8ef4124f-150e-41c4-9b62-f3ef78810fea&lang=en&cr=us&sloc=&p=1)

Edgar
Title: Re: GDI+ scribble
Post by: ecube on February 13, 2010, 06:45:12 AM
Quote from: donkey on February 13, 2010, 06:33:13 AM
Well, it seems that GDI+ 1.1 is not redistributable, you will need either Win7/Vista or install Office 2003 in order to get it. Oh well, XP users are out in the cold.

Edgar

that's  a pretty big oh well, considering they're many of us :) but you can cater to whom you like with your own code, i'm not a big graphic guy, I just wanted to see the latest to come out of the donkey lab, as you almost always produce quality.
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 06:54:32 AM
Quote from: E^cube on February 13, 2010, 06:45:12 AM
that's  a pretty big oh well, considering they're many of us :) but you can cater to whom you like with your own code, i'm not a big graphic guy, I just wanted to see the latest to come out of the donkey lab, as you almost always produce quality.

Hi E^cube,

This was just a little test that I thought some would find interesting, WINVER was set to NTDDI_VISTA so the headers used that as the minimum OS, the main part of the test runs under XP as far as I know, I have no XP boxes to test on (my main XP box is down). For the effects and file functions they can easily enough be rewritten to replace the 3 functions that require 1.1. If I do decide to write an application using GDI+ you can be sure it will be completely compatible with GDI+ 1.0 and Comctl32 6.0.

Edgar
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 07:56:40 AM
OK,

I have done quite a bit of testing of gdiplus.dll files and have found one and only one that will function with XP and provides all of the new API's (version 6.0.3264.0). I have uploaded it to my website:

<File removed, you can get it from the power point viewer here (http://www.masm32.com/board/index.php?topic=13366.msg104278#msg104278)>

To use it DO NOT COPY IT TO THE SYSTEM32 FOLDER !!!!

copy the DLL to the application folder and use the manifest with the <file name="gdiplus.dll"/> line instead of the one with the dependency.

That's it, works great on my XP virtual machine.

Edgar
Title: Re: GDI+ scribble
Post by: ecube on February 13, 2010, 08:05:28 AM
Success! thanks, interesting program  :bg
Title: Re: GDI+ scribble
Post by: donkey on February 13, 2010, 10:54:24 AM
Quote from: donkey on February 13, 2010, 01:38:32 AM
There seems to be a problem when editing zoomed images, there is an artifact in the image that survives even when it is saved so it is not a problem with the zooming process but with garbage being written to the buffer returned by GdipBitmapLockBits. I can't figure out what is wrong though, this image was zoomed 4x then edited, only one pixel was drawn (a red one) then saved...

(http://img693.imageshack.us/img693/2826/testpic.png)

Edgar

FYI - The solution to this problem is to use the flags ImageLockModeWrite + ImageLockModeRead when locking the bitmap data, it seems that using only ImageLockModeWrite produces some undesirable results.

Edgar
Title: Re: GDI+ scribble
Post by: dedndave on February 14, 2010, 02:03:16 AM
a little trip in the "Gdi+ time machine" - lol

http://www.masm32.com/board/index.php?topic=10641.0

it is about a year old and includes manifest info for Gdi+ 1.1, 6.0.3264.0, which Edgar got with PowerPoint Viewer   :P

if i could just lay my hands on that version of the PPT Viewer installer   :bg
Title: Re: GDI+ scribble
Post by: donkey on February 14, 2010, 03:45:01 AM
Hi Dave,

Yeah I saw that afterward as well, seems I already figured out the solution and forgot about it. :U freakin' Alzheim...who are you ?

Edgar
Title: Re: GDI+ scribble
Post by: donkey on February 14, 2010, 06:08:36 AM
I did a bit more experimenting with GDI+ today and have solved a few of the nagging problems I had with it. Background colors for the edit window, having Alpha channel display properly etc...  GDI+ is in no way a match for the old GDI in terms of speed, its very slow so I have tried to get rid of most of the garbage calls or redundancy in the critical parts of the application but its still not possible to draw the background with any speed at all. If I try to update the background while placing a pixel or drawing a line the flashing is unacceptable so I just redraw it when there is no drawing going on. This leads to the problem that alpha values are not properly multiplied while you are drawing so a line looks solid until you release the mouse button. Could be a good thing or a bad thing, i don't like it much. Added a color palette, just some linear colors of no particular significance, I just needed a palette and wanted to do it with GDI+. Also have an Alpha channel slider that adjusts the alpha channel amplitude and some presets. The Check GDI+ button will report the version of GDI+ that was loaded.

I have commented out every function that requires GDI+ 1.1, I will not answer any questions regarding Side by Side assembly or DLL versions, that subject has been beaten to death and nobody seems to have read my tutorial on SxS so I give up. I am looking through the docs for SxS and may write an installer that will allow you to install v1.1 in the SxS folder, lots of work to do on that one though.

Source and exe are included. The manifest requires Comctl32 version 6 (the app doesn't but this demo is cut from a larger project) and any gdi+ will do.

Edgar
Title: Re: GDI+ scribble
Post by: donkey on February 14, 2010, 03:54:42 PM
Quote from: dedndave on February 14, 2010, 02:03:16 AM
if i could just lay my hands on that version of the PPT Viewer installer   :bg

Hi Dave,

The PPT Viewer for Office 2003 version 11.0.5703.0 has gdiplus version 6.0.3264.0 in its application folder.

This one here:

http://www.brothersoft.com/microsoft-powerpoint-viewer-2003-download-63646.html

Can't install it but a quick peek inside the archive shows gdiplus.dll 6.0.3264.0 is there. If you'd like to extract it without installing use an archive program to get the MSI from the exe file then use the following command:

msiexec /a Path to MSI file /qb TARGETDIR=Path to target folder (works on Vista anyway)

Edgar

EDIT : Be sure to run the command prompt as an administrator.
Title: Re: GDI+ scribble
Post by: dedndave on February 14, 2010, 04:18:20 PM
thanks, Edgar   :U
for XP, it installs 1.0 v 5.2.6001.22290
however, i do find the 1.1 dll inside when i manually extract it

what i want to find out is if it is possible to do a complete installation of 1.1 into XP
i know that is not what ms intended, but that doesn't mean it isn't possible   :bg
i need to poke around and see of i can find the CAT file, manifest file, and the regsitry entries

here is what i have in mind:

1) create the "C:\Windows\WinSxS\x86_Microsoft.Windows.GdiPlus_6595b64144ccf1df_1.0.6001.22290_x-ww_f03eb54d" folder
of course, it will have a different name for Gdi+ 1.1
place the dll into that folder

2) place the manifest and security catalog (CAT) files into the "C:\Windows\WinSxS\Manifests" folder

3) create the registry keys in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Installations]

i do not have the information to do all that
i need the following:

1) name of the folder
2) manifest file
3) catalog file
4) registry entries for that version

if you could send me that stuff, it would make it a lot easier than trying to gleen it from extracted files - lol



Title: Re: GDI+ scribble
Post by: donkey on February 14, 2010, 04:24:46 PM
Hi Dave,

It should be possible using the SxS API (http://msdn.microsoft.com/en-us/library/aa376204%28VS.85%29.aspx), I would not try it manually. IAssemblyCache can be used to install and uninstall SxS assemblies but it is documented as Vista+, SxS.DLL is on XP machines though so I think its available. The interface is pretty straight-forward, something out of character for Microsoft's COM team, so it should not be a huge task to write a program to install the SxS entry for it.

Edgar

EDIT: Headers version 0x021008 has the SxS.h and fusion.h header files for side by side assembly.

Whoops, .NET stuff, but it exposes an interop COM interface, a little more complicated but not impossible.

EDIT AGAIN:

The COM interop wrapper is pretty simple:

#include "winsxs.h"
invoke CreateAssemblyCache,offset pIAssemblyCache,NULL
CoInvoke(pIAssemblyCache,IAssemblyCache.Release)