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. COM
  4. COM client structure

COM client structure

Scheduled Pinned Locked Moved COM
comsysadminhelptutorialquestion
3 Posts 3 Posters 1 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.
  • P Offline
    P Offline
    Peter Molnar
    wrote on last edited by
    #1

    Sirs, this is my first COM adventure so I need your advise. I have an in process server with lots of interfaces and even more methods in it. The manufacturer of the dll provides a sample code snippet of how to get pointers to all the interfaces:

    //First object
    HRESULT hr = ::CoCreateInstance(...
    if ( !FAILED( hr ) ) {

    //First interface
    hr = pIUnknown->QueryInterface(...
    if ( !FAILED( hr ) ) {

      //Second interface
      hr = pIUnknown->QueryInterface(...
      if ( !FAILED( hr ) ) {
    
         //Third interface
         hr = pIUnknown->QueryInterface(...
         if ( !FAILED( hr ) ) {
            ...
            //Here comes the code that uses the interfaces
            ...
         } else {
            ...//Third interface failed
         }
      } else {
         ...//Second interface failed
      }
    

    } else {
    ...//First interface failed
    }
    } else {
    ...//CreateInstance failed
    }

    Why are the QI calls NESTED? I tried putting them after each other but the same code taken from the nested structure didn't work (Runtime library: abnormal program termination) although all interfaces were succesfully created. I would like to create the appropriate interfaces in my dialogs' OnInitdialogs and release in the OnDestroyWindow. Is that possible? Any sugggestions? Thanks for your help in advance. Bunburry A subject that is beautiful in itself gives no suggestion to the Artist. It lacks imperfection. (O.Wilde)

    A M 2 Replies Last reply
    0
    • P Peter Molnar

      Sirs, this is my first COM adventure so I need your advise. I have an in process server with lots of interfaces and even more methods in it. The manufacturer of the dll provides a sample code snippet of how to get pointers to all the interfaces:

      //First object
      HRESULT hr = ::CoCreateInstance(...
      if ( !FAILED( hr ) ) {

      //First interface
      hr = pIUnknown->QueryInterface(...
      if ( !FAILED( hr ) ) {

        //Second interface
        hr = pIUnknown->QueryInterface(...
        if ( !FAILED( hr ) ) {
      
           //Third interface
           hr = pIUnknown->QueryInterface(...
           if ( !FAILED( hr ) ) {
              ...
              //Here comes the code that uses the interfaces
              ...
           } else {
              ...//Third interface failed
           }
        } else {
           ...//Second interface failed
        }
      

      } else {
      ...//First interface failed
      }
      } else {
      ...//CreateInstance failed
      }

      Why are the QI calls NESTED? I tried putting them after each other but the same code taken from the nested structure didn't work (Runtime library: abnormal program termination) although all interfaces were succesfully created. I would like to create the appropriate interfaces in my dialogs' OnInitdialogs and release in the OnDestroyWindow. Is that possible? Any sugggestions? Thanks for your help in advance. Bunburry A subject that is beautiful in itself gives no suggestion to the Artist. It lacks imperfection. (O.Wilde)

      A Offline
      A Offline
      Amit Dey
      wrote on last edited by
      #2

      The nested QI() calls are probably because the ability to QI a second interface depends on the success or failure of QI() of the first interface. As to the dialog, OnInitDialog() and OnDestroyWindow() are perfect for creating and releasing COM objects in dialogbased applications. I'm an alien, I'm an alien it's a beautiful life.... Bush

      1 Reply Last reply
      0
      • P Peter Molnar

        Sirs, this is my first COM adventure so I need your advise. I have an in process server with lots of interfaces and even more methods in it. The manufacturer of the dll provides a sample code snippet of how to get pointers to all the interfaces:

        //First object
        HRESULT hr = ::CoCreateInstance(...
        if ( !FAILED( hr ) ) {

        //First interface
        hr = pIUnknown->QueryInterface(...
        if ( !FAILED( hr ) ) {

          //Second interface
          hr = pIUnknown->QueryInterface(...
          if ( !FAILED( hr ) ) {
        
             //Third interface
             hr = pIUnknown->QueryInterface(...
             if ( !FAILED( hr ) ) {
                ...
                //Here comes the code that uses the interfaces
                ...
             } else {
                ...//Third interface failed
             }
          } else {
             ...//Second interface failed
          }
        

        } else {
        ...//First interface failed
        }
        } else {
        ...//CreateInstance failed
        }

        Why are the QI calls NESTED? I tried putting them after each other but the same code taken from the nested structure didn't work (Runtime library: abnormal program termination) although all interfaces were succesfully created. I would like to create the appropriate interfaces in my dialogs' OnInitdialogs and release in the OnDestroyWindow. Is that possible? Any sugggestions? Thanks for your help in advance. Bunburry A subject that is beautiful in itself gives no suggestion to the Artist. It lacks imperfection. (O.Wilde)

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        I can't tell from your code snippet, but the "Here comes the code that uses the interfaces" part probably uses all three interfaces. Thus all three QIs have to succeed before that code can work. And BTW it'll be easier to understand if you replace "!FAILED" with "SUCCEEDED" :) --Mike-- http://home.inreach.com/mdunn/ "The Earth is doomed." -- Rupert Giles :love: your :bob: with :vegemite: and :beer:

        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