COM client structure
-
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)
-
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)
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
-
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)
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: