Problem with SetClipboardData on Win98 [modified]
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
Yes, but not in the Lounge. That's why there's a red "No Programming Quesions, Please" sign at the top of the page... Post in the correct forum and you might just get some assistance with your problem.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
sachinbhave wrote:
this code works fine on Winxp
Then why not you stick to WinXp?:~ :rolleyes:
--[:jig:]-- [My Current Status]
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
I'm going to save you from yourself and move this to the right forum. In future, please don't ask programming questions in the lounge.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
sachinbhave wrote:
but for Win98 I get NULL as return value of SetClipboardData().
No win98 system , to check this. Can you use GetLastError to check what error its returning.
Prasad Notifier using ATL
-
I'm going to save you from yourself and move this to the right forum. In future, please don't ask programming questions in the lounge.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Christian Graus wrote:
move this to the right forum
What work does this require ? I mean, I have no knowledge of databasis and SQL and so, but is this done easily or do you have to dig somewhere to find the thread and reput it in another table ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
-
Christian Graus wrote:
move this to the right forum
What work does this require ? I mean, I have no knowledge of databasis and SQL and so, but is this done easily or do you have to dig somewhere to find the thread and reput it in another table ?
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Well, the first step would be to work here :-) I made the comment because I thought I was going to be the first ( and only lounge ) reply, and I wanted the OP to know that they had posted in the wrong spot still.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
Your memory management is a bit off. Call
GlobalUnlock()
beforeSetClipboardData()
. IfSetClipboardData()
succeeds, the clipboard owns the memory, so you're done. If it fails, you need toGlobalFree()
the memory.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
Well, the first step would be to work here :-) I made the comment because I thought I was going to be the first ( and only lounge ) reply, and I wanted the OP to know that they had posted in the wrong spot still.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Christian Graus wrote:
would be to work here
It was not my intention to do it myself, only wanted to nkow how this works...
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Fair enough - well, as an employee, I get UI to do that, I don't need to be messing with any DB tables directly.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
sachinbhave wrote:
CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() );
It is not necessary to call
GetBuffer()
since you are not modifyingcsText
.sachinbhave wrote:
I get NULL as return value of SetClipboardData().
Which means you should be calling
GetLastError()
to find out why.sachinbhave wrote:
GlobalUnlock( lpLockedMemory );
You should be calling this function regardless of whether
SetClipboardData()
fails or not.sachinbhave wrote:
CloseClipboard();
There's no reason to call this if
SetClipboardData()
fails. Nothing is open at that point.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
I have code written as below : CString csText; HANDLE hData=NULL; m_emailAddress.GetWindowText( csText ); if( (hData=GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, (csText.GetLength()+1) )) ) { LPVOID lpLockedMemory=NULL; lpLockedMemory = GlobalLock( hData ); CopyMemory( lpLockedMemory, csText.GetBuffer(csText.GetLength()), csText.GetLength() ); if( SetClipboardData( CF_TEXT, lpLockedMemory ) == NULL ) { AfxMessageBox( "Unable to set Clipboard data" ); GlobalUnlock( lpLockedMemory ); lpLockedMemory = NULL; CloseClipboard(); return; } } Now, this code works fine on Winxp, but for Win98 I get NULL as return value of SetClipboardData(). Can anyone help on this? -- modified at 4:03 Thursday 24th August, 2006
Did you use from
GetLastError
for see error_**
**_
WhiteSky