Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

copy text string to clipboard

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

783 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