Solved

copy text string to clipboard

Posted on 1997-06-05
2
262 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now