Page Index Toggle Pages: 1 [2]  Send TopicPrint
Very Hot Topic (More than 25 Replies) GDI+ and Network Service (Read 17996 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #15 - Jul 5th, 2011 at 2:45pm
Print Post  
If the intermediate file is what bothers you, try creating an Image instance directly from the HBITMAP (returned by CreateBitmap) instead of loading after SaveToBitmap.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #16 - Jul 5th, 2011 at 6:15pm
Print Post  
After much struggling, I got this idea to work when running normally, but this approach fails when running under IIS.

I use GdipCreateBitmapFromHBITMAP to create a gdi+ bitmap from the handle given to me via Chart.CreateBitmap.

When this code runs normally I get a good new gdip bitmap handle and then I can save to file, but when it runs under IIS I get 0 from GdipCreateBitmapFromHBITMAP. Note that Chart.CreateBitmap DOES give me a proper handle, it just can't get converted to a gdip bitmap for some reason.

Does this give you a clue?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #17 - Jul 5th, 2011 at 6:23pm
Print Post  
I suppose that's why our code doesn't work then Smiley GdipCreateBitmapFromHBITMAP is probably what the GDI+ Bitmap wrapper class calls internally when we use the Bitmap(HBITMAP) constructor in the export method shown above.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #18 - Jul 5th, 2011 at 6:31pm
Print Post  
Great, so now we know where it fails. But why? Smiley And is there anything I can check or do to workaround it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #19 - Jul 5th, 2011 at 6:37pm
Print Post  
How big images are you exporting? Suppose GDI+ has fewer resources when running under a service, then it could fail with large images that work fine from the desktop account.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #20 - Jul 5th, 2011 at 6:49pm
Print Post  
1. I don't think the size is an issue here because it worked when I loaded the same bitmap from a bmp file.

2. I checked the error code that it returns from GdipCreateBitmapFromHBITMAP : '2' which means 'invalid parameter' i think (if my internet search is correct).
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #21 - Jul 5th, 2011 at 8:09pm
Print Post  
There's another reason why this workaround isn't good: I can't enable anti-aliasing so the graphics/text aren't as nice.

Correct me if I am wrong?
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #22 - Jul 6th, 2011 at 8:58pm
Print Post  
Good/bad news:

I figured out what the problem is: Session 0 isolation. In Windows 2008/Vista/7, all services and IIS processes run in 'session 0' which has isolation from hardware devices, etc.

You can read about it here: http://msdn.microsoft.com/en-us/library/ff485857(v=vs.85).aspx

Quote:
the main problem with GDI+ for server-scenarios is that it does not support running in Session 0. Since Session 0 only supports non-interactive functionality, functions that directly or indirectly interact with display devices will therefore receive errors.


This means that if your Chart runs inside a Windows Service or IIS, various GDI+ functions may fail, including saving to file. I tested it in a Windows Service and this is what happens.

This scenario is a huge problem, because people like me want to be able to create pictures from server-side components using your Chart component.


--------------------------

Interesting news:

I found another workaround that first copies the bitmap byte array into a local Picture object (that is not linked to any GDI object/device), and then saves this picture object as a PNG using GDI+.

There may be a better/faster way to do this using Windows API - I don't know.

I wonder whether any other Chart functions don't work when using GDI+...

So, the ball is in your court now - I did everything I can. Please let me know if you find a way to make it work in the Chart. To test it, just run your app as a windows service in win2008.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #23 - Jul 7th, 2011 at 6:20am
Print Post  
Quote:
There's another reason why this workaround isn't good: I can't enable anti-aliasing so the graphics/text aren't as nice. Correct me if I am wrong?


If you export the HBITMAP while GDI+ is enabled, the image will be antialiased.

Quote:
This means that if your Chart runs inside a Windows Service or IIS, various GDI+ functions may fail, including saving to file. I tested it in a Windows Service and this is what happens. This scenario is a huge problem, because people like me want to be able to create pictures from server-side components using your Chart component.


We advertise FlowchartX only as a desktop UI control you know. We have a different server control that can generate images perfectly fine. Now if you prefer using the ActiveX control there, you will have to use the workarounds you've found for the time being.

Quote:
So, the ball is in your court now - I did everything I can. Please let me know if you find a way to make it work in the Chart. To test it, just run your app as a windows service in win2008.


I see, so our developer should spend days to test and look for session 0 isolation work-arounds, or implement a new export method that does not involve HBITMAPs, all that for environment we do not officially support. I'm afraid this will have very low priority in our feature list for next releases, but email us at support@mindfusion.eu to show you have active maintenance and we'll try to find some solution for the next version.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #24 - Jul 7th, 2011 at 6:56am
Print Post  
I'm not sure what I did to get this new attitude. I actually thought I was helping you find a problem in your own software by debugging it for you. Silly me.

Quote:
We advertise FlowchartX only as a desktop UI control you know.


No I didn't know. I never saw anything written on your web site to this effect when we bought it from you. And even now, when I look at the page for the ActiveX control, it says nothing about it not being compatible with server-side applications, nor does it mention the word 'desktop' in any page. Quite the opposite:

Quote:
It is implemented as an ActiveX control and can be easily integrated into any application targeting Microsoft Windows.



Regarding 'active maintenance': We bought the Pro version of the control some time ago. I would have to check the purchase date to see if it is still active.

But, regardless, since this is an issue with your software that is advertised as working with any Windows application, I thought you would be pleased that I helped you find the cause. I guess not.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #25 - Jul 7th, 2011 at 7:17am
Print Post  
Really now, have my most sincere apologies then. However, from all this my understanding is that the problem is in the GdipCreateBitmapFromHBITMAP API function, isn't it? And the only web scenario we ever show for FlowchartX is hosting the control in html object element. So while we'll certainly try to implement a different export method for GDI+, you can see why we cannot give this high priority.
  
Back to top
 
IP Logged
 
baron
YaBB Newbies
*
Offline


1001001001

Posts: 42
Joined: Dec 2nd, 2007
Re: GDI+ and Network Service
Reply #26 - Jul 7th, 2011 at 7:53am
Print Post  
I understand why you wouldn't give this priority. I didn't mean to be pushy.

Until I figured out a workaround for using CreateBitmap, I thought I wouldn't have anti-aliasing because I would have to rely on the SaveToBitmap function instead. But the new workaround makes it workable.

By the way, the web scenario isn't the only one. As I mentioned, Windows services also don't work. So, for example, if you have a server that creates scheduled reports with a chart inside them and then saves or emails them, the same problem would occur. I had to implement the workaround for this case as well.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: GDI+ and Network Service
Reply #27 - Jul 7th, 2011 at 8:14am
Print Post  
Well, I have seen people using this control to draw reports, bar and gantt charts; today I learned it can also be used as a Windows service. Very versatile Smiley
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 
Send TopicPrint