views:

1023

answers:

3

I've got DirectShow based screen capture software. Internally it calls CopyScreenToBitmap function to grab screen. Then the picture is compressed by ffdshow. It works fine as a desktop application, but as window service, on certain computers it does not work (black picture). I've set 'Allow service to interact with desktop' and run that service on current user account. Any ideas what could be wrong?

I test it on windows XP, but it is expected to work on Vista and 7 as well.

Yes it works as desktop application on all computers, but on some of them (on majority of them) it fails as a service.

+1  A: 

Have you tested that the desktop application succeeds on the same computers it fails as a service?

Magnus Skog
+3  A: 

As I understand it, a change was made in Vista that moved services onto a separate desktop from the console user. While you have ticked the box that "allows access" to the desktop, I think you still have to pragmatically switch your service to use that desktop.

Here is a blog post with some useful info and examples.

Jon Grant
+1 Jon is probably right. I recognize this issue.
Magnus Skog
That's a good answer, too, but it was too short to help jump over my knowledge gap :-).
bezieur
+2  A: 

Try this in addition to allowing access to the desktop:

  1. Enumerate all Window Stations: EnumWindowStations
  2. Find the window station for the logged on user, and make it your process' window station: SetProcessWindowStation - see example in this thread
  3. Then set the desktop for your current thread to the default desktop of the window station also here
  4. Then get the DC of the desktop using one of a few methods, including

    CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL)

    Good luck

mjmarsh
That's the point! Thank all of you for a help. Additionally I've found the article: http://www.codeproject.com/KB/system/SystemTrayIconInSvc.aspx which covers that issue as well.
bezieur