3

Update: This issue has been resolved.

you can read about the solution in here: Creating a process in a non-zero session from a service in windows-2008-server?

Thanks everyone!


Hi,

I am trying to use Clipboard API (in Delphi) to extract images from Word documents. my code works OK in Windows XP/2003 but in windows 2008 64 bit it doesn't work. in win 2008 i get an error saying that Clipboard.Formats is empty and doesn't contain any format.

The image seems to be copied to the Clipboard (i can see it in the clipboard via Word) but when i try to ask the clipboard what format does he have it said it doesn't have any formats.

how can i access the clipboard programmatically on win 2008/Vista? from what i know of 2008 64 bit, it might be a security issue...

here is the code snippet:

This is how i am trying to copy the Image to the clipboard:

W.ActiveDocument.InlineShapes.Item(1).Select; // W is a word ole object
W.Selection.Copy;

and this is how i try to paste it.

  Clipboard.Open;
      Write2DebugFile('FormatCount = ' + IntToStr(Clipboard.FormatCount)); // FormatCount=0 
      For JJ := 1 to Clipboard.FormatCount Do
          Write2DebugFile('#'+ IntToStr(JJ) + ':' + IntToStr(Clipboard.Formats[JJ]));
      If (Clipboard.HasFormat(CF_BITMAP)) or
        (Clipboard.HasFormat(CF_PICTURE)) or
        (Clipboard.HasFormat(CF_METAFILEPICT)) then    // all HasFormat calls returns false.
      Begin
       Jpeg := TJPEGImage.Create;
       Bitmap := TBitmap.Create;
       Bitmap.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
       Jpeg.Assign(Bitmap);
       Jpeg.SaveToFile(JpgFileN);
       try Jpeg.Free; except; end;
       ResizeImage(JpgFileN,750);
       Write2DebugFile('Saving ' + JpgFileN);
      End
      else  Write2DebugFile('Doesnt have the right format');

Thanks in advance, Itay

Community
  • 1
  • 1
Itay Levin
  • 1,579
  • 2
  • 16
  • 23
  • My guess would be that Word is storing the data using 64-bit memory that your 32-bit Delphi app cannot access. – Remy Lebeau Feb 04 '10 at 02:58
  • also, another issue might be because i'm running it as a service... – Itay Levin Feb 04 '10 at 16:06
  • i can't seems to access anyof the Clipboard api functions(neither from the Clipboard obj nor from the Win32API). I have created a test cons' application which has worked fine. Also i created a monitoring application of the clipbard contents. and i see that my original application does insert images into the clipboard (using Copy, not directly) but any direct call to the clipbard from my original application fails. My orig. code is inside a dll which another executable is running that this exectuable is started by a win service. Service -> Exectuable -> DLL (doesn't work) Exectuable - (working) – Itay Levin Feb 07 '10 at 17:03
  • 1
    @Remy: Word is still a 32 bit app. – Remko Feb 09 '10 at 07:38

1 Answers1

2

AFAIR, appear that M$ doesn't allow services to interact with desktop (which is needed to use clipboard) in Win2008.

Fabricio Araujo
  • 3,810
  • 3
  • 28
  • 43
  • 1
    From a technet article: "In Windows Vista and Windows Server 2008, support for interactive services has been removed to mitigate this security risk" Article is technet.microsoft.com/en-us/library/cc756339(WS.10). – DaveE Feb 08 '10 at 17:37
  • 1
    Fabricio is right, your service lives in session 0 while the word instance is living in another session. It is not possible to copy/paste between sessions. 64 bit has nothing to do with this. One way to solve it would be to create a process in the same session as the word instance (http://www.remkoweijnen.nl/blog/2007/10/20/how-to-launch-a-process-in-a-terminal-session/) – Remko Feb 09 '10 at 07:38
  • Thanks Remko...Yes it is correct i have found out that the word process is running in session 3 while the originial exe is running in session 0 (because it has been run by the service). Now, knowing that my issue remains how to create the ole object in session 0, i have seen that it is possible to CreateProcess in session 0 by specifying StartInfo Parameter called lpDesktop with the following string 'winsta0\default'. do you know of a way to instantiate a word ole object with this parameter. i'm using CreateOleObject('Word.Application') in order to instantiate the word. i really need it. – Itay Levin Feb 09 '10 at 14:32
  • 1
    @Itay: you can open a new question for that. – Remko Feb 10 '10 at 07:01
  • I have opened a new followup-question related to that issue. Thanks for everyone who has been viewing this thread. http://stackoverflow.com/questions/2237696/creating-a-process-in-a-non-zero-session-from-a-service-in-windows-2008-server – Itay Levin Feb 10 '10 at 15:01