How to Cleanly Destroy WebBrowser Control

前端 未结 3 457
夕颜
夕颜 2021-02-04 21:09

I am using ATL in VisualC++10 to host browser control. My code is similar to this example: http://msdn.microsoft.com/en-us/library/9d0714y1(v=vs.80).aspx

Difference is I

3条回答
  •  粉色の甜心
    2021-02-04 21:44

    My experience is that some calls might need message processing to function properly. Try to pump some messages between your calls to Navigate, Stop etc. When working with the web browser interfaces I PostMessage myself often to trigger the next step to make sure the previous step had time to complete.

    The problem might be related to your child thread. You cannot access web browser interfaces between threads without some additional work. COM needs to be initialized as single-threaded apartment (STA). And you need to follow the rules of STAs:

    • Every object should live on only one thread (within a single-threaded apartment). Initialize the COM library for each thread.
    • Marshal all pointers to objects when passing them between apartments.
    • Each single-threaded apartment must have a message loop to handle calls from other processes and apartments within the same process. Single-threaded apartments without objects (client only) also need a message loop to dispatch the broadcast messages that some applications use.
    • ...

提交回复
热议问题