Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

copy text string to clipboard

Posted on 1997-06-05
2
Medium Priority
?
328 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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