Programming C++Builder TCppWebBrowser/TWebBrowser has been set to the edit mode, but the copy and paste do not work

This is because you do not call the OleInitialize function. As the OLE operation is not thread-safe, so operation to the memory will cause failure or error. OleInitialize ensure that the concurrent modules run in an STA mode (that is, a single-threaded mode)  to avoid the sharing of resources error. Therefore, in a program's starting function WinMain, we should make some changes as following.
WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)
(
    OleInitialize (NULL);
    try
    (
       ... ... //Normal statements
    ) catch (...)
    (
       ... ... //Normal statements
    )
    OleUninitialize ();
    return 0;
)

In a C-Builder program, you could also call the OleInitialize function in the main form's OnCreate event, like below mode. Last, call the OleUninitialize function when the form destroy.

void __fastcall TForm1::FormCreate(TObject *Sender)
{
    OleInitialize(NULL);   
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
    OleUninitialize();   
}

In a Delphi program, is in a same way.


Add comment


Security code
Refresh

Programming - C++Builder