Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. AfxOleInit, Rama and a puzzle!

AfxOleInit, Rama and a puzzle!

Scheduled Pinned Locked Moved Managed C++/CLI
htmlcomhostingquestion
3 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #1

    First, Thanks to Rama :-) A big thank you in fact. I put AfxOleInit and it worked Now the puzzle :- Even without the call to AfxOleInit, it worked when I remove the remoting code! Can someone explain how that could occur? Nish


    Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

    R 1 Reply Last reply
    0
    • N Nish Nishant

      First, Thanks to Rama :-) A big thank you in fact. I put AfxOleInit and it worked Now the puzzle :- Even without the call to AfxOleInit, it worked when I remove the remoting code! Can someone explain how that could occur? Nish


      Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

      R Offline
      R Offline
      Rama Krishna Vavilala
      wrote on last edited by
      #2

      I had to look and go through your code to find this out. 1. AfxEnableControlContainer is automatically called by CHtmlView so it is not necessary. But still it is a good practice to have it in the InitInstance. 2. MFC requires AfxOleInit in order for control containment to work and I am surprised to see that in VS.NET it is automatically called during CreateControl. If that fails MFC cannot create controls. Now to the actual answer. Activator.GetObject or Activator.CreateInstance initialize COM automatically if it is not initialized and the default is to initialize is COINT_MULTITHREADED. So when MFC tries to call AfxOleInit (COINIT_APARTMENTTHREADED) the call fails because you cannot change the apartment type. So the control creation fails. But when you call AfxOleInit in InitInstance Activator.GetObject sees that COM is initialized so it doesnot do anything and everything is fine. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

      N 1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        I had to look and go through your code to find this out. 1. AfxEnableControlContainer is automatically called by CHtmlView so it is not necessary. But still it is a good practice to have it in the InitInstance. 2. MFC requires AfxOleInit in order for control containment to work and I am surprised to see that in VS.NET it is automatically called during CreateControl. If that fails MFC cannot create controls. Now to the actual answer. Activator.GetObject or Activator.CreateInstance initialize COM automatically if it is not initialized and the default is to initialize is COINT_MULTITHREADED. So when MFC tries to call AfxOleInit (COINIT_APARTMENTTHREADED) the call fails because you cannot change the apartment type. So the control creation fails. But when you call AfxOleInit in InitInstance Activator.GetObject sees that COM is initialized so it doesnot do anything and everything is fine. Step back, rub your eyes, take a deep breath, stretch a bit, and reflect on the relative importance of CP, CG, the age / travel time sustained by supposedly 'fresh' cheese curds, and Life in General. - Shog9

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Rama Krishna wrote: AfxEnableControlContainer is automatically called by CHtmlView so it is not necessary. But still it is a good practice to have it in the InitInstance Yes, in fact I did not add it myself. The app wiz had put it there for me. Rama Krishna wrote: MFC requires AfxOleInit in order for control containment to work and I am surprised to see that in VS.NET it is automatically called during CreateControl I had looked at the different overloads of CWnd::CreateControl but had not found any call to AfxOleInit, but just now I found that COleControlSite::CreateControl does indeed call AfxOleInit Rama Krishna wrote: Now to the actual answer. Brilliant!!! Thanks :-) Regards, Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups