access violation creating webbrowser2 control
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: access violation creating webbrowser2 control

  1. #1
    Join Date
    Jun 2002

    Question access violation creating webbrowser2 control

    i'm trying to add a webbrowser2 control to my app. i am receiving an 'access violation' when i attempt to create it. access violation is pointing to the following Cwnd function:

    BOOL CWnd::InitControlContainer()
    m_pCtrlCont = afxOccManager->CreateContainer(this);

    my class definition and 'onupdate' function follows:

    class CInitialWnd : public CWnd


    CWebBrowser2 m_target;

    int CInitialWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
    if (CWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    m_target.Create(NULL, dwStyle, CRect(0, 0, 100, 100), this, ID_BROWSER_TARGET);

    return 0;

    thanks in advance,


  2. #2
    Join Date
    Dec 2002
    Hi lordhairball !

    Well, I know at least part of the issue here. But an important
    thing is, there's really not much info in your post so I had to
    make assumptions about what you did. I hope I'm right !

    I assumed that you wrote your MFC part by hand and did not
    use AppWizard to create the project.

    The issue here is that the first thing that must be called when
    using controls like this is AfxEnableControlContainer(), otherwise
    the variable that is causing the crash is not initialized and you
    won't have support for anything OLE.

    Using a regular appwizard generated project wont display this
    problem unless you remove some stuff from the settings that
    are generated for you.

    So in your app classes InitInstance call

    Also, I don't think the control will be visible untill after you
    Actually I know this so maybe I create it wrong !

    And if I'm wrong I'm gonna be really embarassed


  3. #3
    Join Date
    Nov 2013

    Re: access violation creating webbrowser2 control

    11 years later:

    I have been trying to make an MFC OLE C++/CLI Wrapper for a C# User Control but had a problem with "Access Violation in InitControlContainer" when creating the managed control for several days now.

    Your posts solved my problem.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center