Pasting from the clipboard

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
imekon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 16, 2007 3:41 pm

Pasting from the clipboard

Post by imekon » Sun Dec 16, 2007 10:05 pm

This works on the Mac but crashes on Windows:

Code: Select all

if (wxTheClipboard->Open())
{
    if (wxTheClipboard->IsSupported(m_dataFormat))
    {
        wxCustomDataObject data(m_dataFormat);
              
        if (wxTheClipboard->GetData(data))
        {
            ...
        }
    }
}
It crashes inside GetData:

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00597242 in wxDataObjectBase::IsSupported (this=0x22ef20, [email protected],
    dir=Get) at ../../src/common/dobjcmn.cpp:57
57          size_t nFormatCount = GetFormatCount( dir );
Current language:  auto; currently c++

#0  0x00597242 in wxDataObjectBase::IsSupported (this=0x22ef20,
    [email protected], dir=Get) at ../../src/common/dobjcmn.cpp:57
#1  0x007668c8 in wxDataObject::IsSupportedFormat (this=0x22ef20,
    [email protected]) at ../../include/wx/msw/ole/dataobj.h:41
#2  0x0059a0db in wxIDataObject::QueryGetData (this=0x2c5d5c0,
    pformatetc=0x22ef30) at ../../src/msw/ole/dataobj.cpp:570
#3  0x005998ba in wxIDataObject::GetData (this=0x2c5d5c0,
    pformatetcIn=0x22ef30, pmedium=0x22ef10)
    at ../../src/msw/ole/dataobj.cpp:285
#4  0x77552ffc in ole32!CLSIDFromOle1Class ()
   from C:\WINDOWS\system32\ole32.dll
#5  0x02c5d5c0 in ?? ()
#6  0x0022ef30 in ?? ()
#7  0x0022ef10 in ?? ()
#8  0x0022f450 in ?? ()
#9  0x0052b2a8 in wxWindowCreationHook::~wxWindowCreationHook ()
    at ../../include/wx/msw/private.h:892
#10 0x005f77cb in wxClipboard::GetData (this=0x2c5d598, [email protected])
    at ../../src/msw/clipbrd.cpp:835
Any ideas anyone?

imekon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 16, 2007 3:41 pm

Post by imekon » Mon Dec 17, 2007 9:13 pm

Here's a fragment from a small application to demonstrate the problem:

Code: Select all

    m_dataFormat.SetId(_T("TestAppData"));
The clipboard copy code...

Code: Select all

void MainFrame::OnCopyClick( wxCommandEvent& event )
{
    wxMemoryOutputStream stream;
    
    char *buffer = new char[256];
    
    memset(buffer, 0, 256);
    
    stream.Write(buffer, 256);
    
    if (wxTheClipboard->Open())
    {
        wxCustomDataObject data(m_dataFormat);
        
        int size = stream.GetSize();
        
        char *raw = new char[size];
        
        stream.CopyTo(raw, size);
        
        data.Alloc(size);
        data.SetData(size, raw);
        
        wxTheClipboard->SetData(&data);
        
        wxTheClipboard->Close();
        
        delete raw;
    }
}
The paste code...

Code: Select all

void MainFrame::OnPasteClick( wxCommandEvent& event )
{
    if (wxTheClipboard->Open())
    {
        if (wxTheClipboard->IsSupported(m_dataFormat))
        {
            wxCustomDataObject data(m_dataFormat);
            
            if (wxTheClipboard->GetData(data))
            {
                wxMemoryInputStream stream(data.GetData(), data.GetSize());

                char *buffer = new char[256];
                
                stream.Read(buffer, 256);
                
                delete buffer;
            }
        }
        
        wxTheClipboard->Close();
    }
}
This version simply exits if you paste (runtime error in MSVCRT.DLL)

imekon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 16, 2007 3:41 pm

Post by imekon » Mon Dec 17, 2007 9:16 pm

You can find the full DialogBlocks project here: http://www.imekon.pwp.blueyonder.co.uk/wx/wxclip.zip.

kshitij_ds
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Jun 25, 2008 3:37 pm

Post by kshitij_ds » Mon Nov 24, 2008 9:29 pm

hi Imekon,

I am having the same issue. It looks like you posted this issue an year ago... Did u come up with any solution?

Thanks,
Kshitij.

Post Reply