Article View: borland.public.cppbuilder.nativeapi
Article #8435Writing to Clipboard from a service
From: nicolasr
Date: Sat, 23 Oct 2004 00:39
Date: Sat, 23 Oct 2004 00:39
41 lines
2059 bytes
2059 bytes
Hi,
I want to write to the Clipboard of the currently
logged on user from within a Windows service.
I've created the service with BCBs TService class.
To write to the clipboard I first tried the global
TClipboard instance. Since this didn't work I tried
to use the APIs directly, as described in the MSDN help.
Like this:
if(FALSE == OpenClipboard(NULL))
{
Log("OpenClipboard failed");
return;
}
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dataSize+1);
void* ptr = GlobalLock(hGlobal);
CopyMemory(ptr, buffer, dataSize+1);
if(FALSE == SetClipboardData(CF_TEXT, hGlobal))
Log(GetLastErrorString());
GlobalUnlock(hGlobal);
GlobalFree(hGlobal);
CloseClipboard();
However, the text never arrives in the clipboard. The problem
is that I don't get any error log so I don't know what went wrong.
I'm not very familiar with security issues so I don't know whether
the service can write to the clipboard at all.
By the way, I switched the services Interactive property to 'true'
but that didn't help.
Any ideas welcome!
Nick
Technical Details
Message-ID:
<4179a85e$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f2ddb07f5aa054ba,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "nicolasr" <nicolasrNOSPAMATSIGNgmx.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Writing to Clipboard from a service Date: Sat, 23 Oct 2004 02:39:57 +0200 Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 80.133.177.68 Message-ID: <4179a85e$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1098491998 80.133.177.68 (22 Oct 2004 17:39:58 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in.nuthinbutnews.com!in.nntp.be!caladan.arrakis.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail