Solved

copy text string to clipboard

Posted on 1997-06-05
2
319 Views
Last Modified: 2013-12-03
I wish to copy a text string to Windows' clipboard. I'm encountering type errors when trying to copy my local string into the allocated memory block. The code segment folows. The commented section in the middle is where I am encountering the problem.  FYI: I am using Borland C++ v5.01. Thanks.

int i, wLen;                  // counter & text length variables
HGLOBAL hGMem;    // global handle to a memory block
void FAR* lpGMem;    // pointer to the memory block
char *lpText = "This is a test";   // pointer to the text string

wLen = strlen(lpText);
hGMem = GlobalAlloc(GHND, (DWORD) wLen + 1);
lpGMem = GlobalLock(hGMem);

// copy the string pointed to by lpText into the memory block
// This is where I'm having the problem. I'm getting "not an allowed type"
// errors here. How do I get the memory block to hold my text? I've tried:

//for (i=0; i<wLen; i++)
//      *lpGMem = *lpText++;

// and

// *lpGMem = * lpText;

// with no success.

GlobalUnlock(hGMem);

if (OpenClipboard()) {
      EmptyClipboard();
   SetClipboardData(CF_TEXT, hGMem);
   CloseClipboard();
   }
0
Comment
Question by:MooDave
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
slp earned 50 total points
ID: 1397874
How's about:

strcpy( *lpGMem, *lpText );
0
 

Expert Comment

by:joneva
ID: 1397875
strcpy was a good place to start, but slp's answer:
strcpy( *lpGMem, *lpText );
gave me the "not an allowed type" error.

joneva's suggestion of:
strcpy( lpGMem, lpText ); with casting, turned out to be the solution. The final solution was:

strcpy( (char *)lpGMem, lpText );

Many thanks to joneva (is it possible to give her some points for this?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question