Click here to Skip to main content
Licence 
First Posted 2 Apr 2002
Views 79,681
Bookmarked 43 times

How to find the name for interfaces implemented by a COM object

By | 2 Apr 2002 | Article
The article descibes how can you find the interfaces implemented by a COM object

Introduction

This is a class that helps you to find the interfaces implemented by a COM object. Here's how you can use that MsgBox method

QI::MsgBox( yourCOMObject ); 

Code Listing

#include <atlbase.h>
#include <string>
#include <sstream>
class QI : protected CRegKey,
#ifdef _UNICODE
    public std::wstringstream
#else
    public std::stringstream
#endif
{
protected:
    virtual tstring Query( IUnknown* pUnk )
    {
        if ( pUnk != NULL && ( ERROR_SUCCESS == 
            Open( HKEY_CLASSES_ROOT, _T("Interface") ) ) )
        {
            TCHAR szKeyName[1024] = _T("");
            for ( int i = 0; ERROR_SUCCESS == 
                RegEnumKey( m_hKey, i, szKeyName, 1024 ); i++ )
            {
                USES_CONVERSION;
                CLSID clsID = CLSID_NULL;
                if ( SUCCEEDED( CLSIDFromString( T2OLE(szKeyName), 
                    &clsID ) ) )
                {
                    CComPtr<IUnknown> spObject = NULL;
                    if ( SUCCEEDED( pUnk->QueryInterface( clsID, 
                        (void**)&spObject ) ) )
                    {
                        TCHAR szValue[1024] = _T(""); 
                        LONG ncbValue = 1024;
                        if ( ERROR_SUCCESS == RegQueryValue( m_hKey, 
                            szKeyName, szValue, &ncbValue ) )
                            *this << tstring(szValue) + _T("\r\n");
                    }
                }
            }
            Close();
        }
        return str();
    }

public:
    static void MsgBox( IUnknown* pUnk )
    {
        QI objQI;
        MessageBox( NULL, objQI.Query( pUnk ).c_str(),
            _T("The object implements:"), MB_ICONINFORMATION );
    }
};

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Mikelangelo

Web Developer

Romania Romania

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralExcellent Utility - Small and Cute PinmemberSharjith18:52 2 Apr '09  
GeneralCan't query clsid's PinmemberRené Greiner3:42 8 Apr '02  
GeneralRe: Can't query clsid's PinmemberMikelangelo8:21 8 Apr '02  
GeneralRe: Can't query clsid's PinmemberRené Greiner23:39 9 Apr '02  
GeneralRe: Can't query clsid's PinmemberMikelangelo23:44 9 Apr '02  
GeneralRe: Can't query clsid's PinmemberMikelangelo23:51 9 Apr '02  
GeneralRe: Can't query clsid's PinmemberRené Greiner0:01 10 Apr '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 3 Apr 2002
Article Copyright 2002 by Mikelangelo
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid