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. Implementation two interfaces in one class

Implementation two interfaces in one class

Scheduled Pinned Locked Moved COM
help
14 Posts 5 Posters 15 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.
  • V venkatesh52867

    Hi, i have implemented two interfaces in class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { ....

    STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
    {
    HRESULT hr;
    if (IID_IUnknown == riid ||
    IID_ICredentialProvider == riid || IID_ICredentialProviderSetUserArray )
    {
    *ppv = this;
    reinterpret_cast<IUnknown*>(*ppv)->AddRef();
    hr = S_OK;
    }
    else
    {
    *ppv = NULL;
    hr = E_NOINTERFACE;
    }
    return hr;
    }

    ........ }; it is building with out errors .but when i execute dll logonui is crashing .how can implement two interfaces in one class please help me

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    venkatesh52867 wrote:

    but when i execute dll logonui is crashing

    You need to trace to the point of the error and show the code that crashes and the reason.

    Use the best guess

    V 1 Reply Last reply
    0
    • L Lost User

      venkatesh52867 wrote:

      but when i execute dll logonui is crashing

      You need to trace to the point of the error and show the code that crashes and the reason.

      Use the best guess

      V Offline
      V Offline
      venkatesh52867
      wrote on last edited by
      #3

      Hi, Problem is this || IID_ICredentialProviderSetUserArray when i call IID_ICredentialProviderSetUserArray interface through Quareyinterface dll is crashing without implementing ICredentialProviderSetUserArray interface dll is working is fine . thanks

      L V 2 Replies Last reply
      0
      • V venkatesh52867

        Hi, Problem is this || IID_ICredentialProviderSetUserArray when i call IID_ICredentialProviderSetUserArray interface through Quareyinterface dll is crashing without implementing ICredentialProviderSetUserArray interface dll is working is fine . thanks

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        I'm sorry, but no one can guess what your code is doing to cause the crash. As I said before, use your debugger to trace through it and identify exactly what is happening.

        Use the best guess

        1 Reply Last reply
        0
        • V venkatesh52867

          Hi, Problem is this || IID_ICredentialProviderSetUserArray when i call IID_ICredentialProviderSetUserArray interface through Quareyinterface dll is crashing without implementing ICredentialProviderSetUserArray interface dll is working is fine . thanks

          V Offline
          V Offline
          venkatesh52867
          wrote on last edited by
          #5

          Hi, please check this code.i am highlighted with bold that code add then it is crashing. #pragma once #include #include #include #include "PasswordResetCredential.h" #include "helpers.h" class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { public: // IUnknown STDMETHOD_(ULONG, AddRef)() { return _cRef++; } STDMETHOD_(ULONG, Release)() { LONG cRef = _cRef--; if (!cRef) { delete this; } return cRef; } STDMETHOD (QueryInterface)(REFIID riid, void** ppv) { HRESULT hr; if (IID_IUnknown == riid || IID_ICredentialProvider == riid ||IID_ICredentialProviderSetUserArray==riid) { *ppv = this; reinterpret_cast(*ppv)->AddRef(); hr = S_OK; } else { *ppv = NULL; hr = E_NOINTERFACE; } return hr; } public: IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags); IFACEMETHODIMP SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs); IFACEMETHODIMP Advise(__in ICredentialProviderEvents* pcpe, UINT_PTR upAdviseContext); IFACEMETHODIMP UnAdvise(); IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount); IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd); IFACEMETHODIMP GetCredentialCount(__out DWORD* pdwCount, __out DWORD* pdwDefault, __out BOOL* pbAutoLogonWithDefault); IFACEMETHODIMP GetCredentialAt(DWORD dwIndex, __out ICredentialProviderCredential** ppcpc); IFACEMETHODIMP SetUserArray (__in ICredentialProviderUserArray * users); friend HRESULT CSampleProvider_CreateInstance(REFIID riid, __deref_out void** ppv); protected: CSampleProvider(); __override ~CSampleProvider(); private: void _CleanUpAllCredentials(); private: LONG _cRef; CSampleCredential **_rgpCredentials; // Pointers to the credentials which will be enumerated by this // Provider. ICredentialProvider *_pWrappedProvider; // Our wrapped provider.

          L 3 Replies Last reply
          0
          • V venkatesh52867

            Hi, please check this code.i am highlighted with bold that code add then it is crashing. #pragma once #include #include #include #include "PasswordResetCredential.h" #include "helpers.h" class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { public: // IUnknown STDMETHOD_(ULONG, AddRef)() { return _cRef++; } STDMETHOD_(ULONG, Release)() { LONG cRef = _cRef--; if (!cRef) { delete this; } return cRef; } STDMETHOD (QueryInterface)(REFIID riid, void** ppv) { HRESULT hr; if (IID_IUnknown == riid || IID_ICredentialProvider == riid ||IID_ICredentialProviderSetUserArray==riid) { *ppv = this; reinterpret_cast(*ppv)->AddRef(); hr = S_OK; } else { *ppv = NULL; hr = E_NOINTERFACE; } return hr; } public: IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags); IFACEMETHODIMP SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs); IFACEMETHODIMP Advise(__in ICredentialProviderEvents* pcpe, UINT_PTR upAdviseContext); IFACEMETHODIMP UnAdvise(); IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount); IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd); IFACEMETHODIMP GetCredentialCount(__out DWORD* pdwCount, __out DWORD* pdwDefault, __out BOOL* pbAutoLogonWithDefault); IFACEMETHODIMP GetCredentialAt(DWORD dwIndex, __out ICredentialProviderCredential** ppcpc); IFACEMETHODIMP SetUserArray (__in ICredentialProviderUserArray * users); friend HRESULT CSampleProvider_CreateInstance(REFIID riid, __deref_out void** ppv); protected: CSampleProvider(); __override ~CSampleProvider(); private: void _CleanUpAllCredentials(); private: LONG _cRef; CSampleCredential **_rgpCredentials; // Pointers to the credentials which will be enumerated by this // Provider. ICredentialProvider *_pWrappedProvider; // Our wrapped provider.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            Please format your code properly between <pre> tags, like:

            STDMETHOD_(ULONG, Release)()
            {
            LONG cRef = _cRef--;
            if (!cRef)
            {
            delete this;
            }
            return cRef;
            }

            Use the best guess

            1 Reply Last reply
            0
            • V venkatesh52867

              Hi, please check this code.i am highlighted with bold that code add then it is crashing. #pragma once #include #include #include #include "PasswordResetCredential.h" #include "helpers.h" class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { public: // IUnknown STDMETHOD_(ULONG, AddRef)() { return _cRef++; } STDMETHOD_(ULONG, Release)() { LONG cRef = _cRef--; if (!cRef) { delete this; } return cRef; } STDMETHOD (QueryInterface)(REFIID riid, void** ppv) { HRESULT hr; if (IID_IUnknown == riid || IID_ICredentialProvider == riid ||IID_ICredentialProviderSetUserArray==riid) { *ppv = this; reinterpret_cast(*ppv)->AddRef(); hr = S_OK; } else { *ppv = NULL; hr = E_NOINTERFACE; } return hr; } public: IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags); IFACEMETHODIMP SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs); IFACEMETHODIMP Advise(__in ICredentialProviderEvents* pcpe, UINT_PTR upAdviseContext); IFACEMETHODIMP UnAdvise(); IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount); IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd); IFACEMETHODIMP GetCredentialCount(__out DWORD* pdwCount, __out DWORD* pdwDefault, __out BOOL* pbAutoLogonWithDefault); IFACEMETHODIMP GetCredentialAt(DWORD dwIndex, __out ICredentialProviderCredential** ppcpc); IFACEMETHODIMP SetUserArray (__in ICredentialProviderUserArray * users); friend HRESULT CSampleProvider_CreateInstance(REFIID riid, __deref_out void** ppv); protected: CSampleProvider(); __override ~CSampleProvider(); private: void _CleanUpAllCredentials(); private: LONG _cRef; CSampleCredential **_rgpCredentials; // Pointers to the credentials which will be enumerated by this // Provider. ICredentialProvider *_pWrappedProvider; // Our wrapped provider.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              if (IID_IUnknown == riid ||
              IID_ICredentialProvider == riid ||
              IID_ICredentialProviderSetUserArray)
              {

              Do you see something missing here?

              Use the best guess

              V 1 Reply Last reply
              0
              • L Lost User

                if (IID_IUnknown == riid ||
                IID_ICredentialProvider == riid ||
                IID_ICredentialProviderSetUserArray)
                {

                Do you see something missing here?

                Use the best guess

                V Offline
                V Offline
                venkatesh52867
                wrote on last edited by
                #8

                hi, ok but that is not problem when i called ICredentialProviderSetUserArray ==riid probblem is occurring if (IID_IUnknown == riid || IID_ICredentialProvider == riid || IID_ICredentialProviderSetUserArray ==riid) { Thanks

                L 1 Reply Last reply
                0
                • V venkatesh52867

                  hi, ok but that is not problem when i called ICredentialProviderSetUserArray ==riid probblem is occurring if (IID_IUnknown == riid || IID_ICredentialProvider == riid || IID_ICredentialProviderSetUserArray ==riid) { Thanks

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  You really need to do this[^]. Without a lot more information about what is actually happening at the time of the crash it's anyone's guess.

                  Use the best guess

                  E 1 Reply Last reply
                  0
                  • V venkatesh52867

                    Hi, please check this code.i am highlighted with bold that code add then it is crashing. #pragma once #include #include #include #include "PasswordResetCredential.h" #include "helpers.h" class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { public: // IUnknown STDMETHOD_(ULONG, AddRef)() { return _cRef++; } STDMETHOD_(ULONG, Release)() { LONG cRef = _cRef--; if (!cRef) { delete this; } return cRef; } STDMETHOD (QueryInterface)(REFIID riid, void** ppv) { HRESULT hr; if (IID_IUnknown == riid || IID_ICredentialProvider == riid ||IID_ICredentialProviderSetUserArray==riid) { *ppv = this; reinterpret_cast(*ppv)->AddRef(); hr = S_OK; } else { *ppv = NULL; hr = E_NOINTERFACE; } return hr; } public: IFACEMETHODIMP SetUsageScenario(CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus, DWORD dwFlags); IFACEMETHODIMP SetSerialization(const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs); IFACEMETHODIMP Advise(__in ICredentialProviderEvents* pcpe, UINT_PTR upAdviseContext); IFACEMETHODIMP UnAdvise(); IFACEMETHODIMP GetFieldDescriptorCount(__out DWORD* pdwCount); IFACEMETHODIMP GetFieldDescriptorAt(DWORD dwIndex, __deref_out CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd); IFACEMETHODIMP GetCredentialCount(__out DWORD* pdwCount, __out DWORD* pdwDefault, __out BOOL* pbAutoLogonWithDefault); IFACEMETHODIMP GetCredentialAt(DWORD dwIndex, __out ICredentialProviderCredential** ppcpc); IFACEMETHODIMP SetUserArray (__in ICredentialProviderUserArray * users); friend HRESULT CSampleProvider_CreateInstance(REFIID riid, __deref_out void** ppv); protected: CSampleProvider(); __override ~CSampleProvider(); private: void _CleanUpAllCredentials(); private: LONG _cRef; CSampleCredential **_rgpCredentials; // Pointers to the credentials which will be enumerated by this // Provider. ICredentialProvider *_pWrappedProvider; // Our wrapped provider.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #10

                    www.163.com

                    1 Reply Last reply
                    0
                    • L Lost User

                      You really need to do this[^]. Without a lot more information about what is actually happening at the time of the crash it's anyone's guess.

                      Use the best guess

                      E Offline
                      E Offline
                      ExcellentOrg
                      wrote on last edited by
                      #11

                      Richard, Venkatesh Are you certain that the old object is not getting out of scope when you create new. When you create multiple objects, chances are that you are not maintaining reference counts correctly so there is a small chance that object is actually removed or marked for removal when client attempts to access ... As Richard quotes, this is my best guess :)

                      L 1 Reply Last reply
                      0
                      • E ExcellentOrg

                        Richard, Venkatesh Are you certain that the old object is not getting out of scope when you create new. When you create multiple objects, chances are that you are not maintaining reference counts correctly so there is a small chance that object is actually removed or marked for removal when client attempts to access ... As Richard quotes, this is my best guess :)

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #12

                        It's been over a month; one can only assume OP fixed their code.

                        Use the best guess

                        1 Reply Last reply
                        0
                        • V venkatesh52867

                          Hi, i have implemented two interfaces in class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { ....

                          STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
                          {
                          HRESULT hr;
                          if (IID_IUnknown == riid ||
                          IID_ICredentialProvider == riid || IID_ICredentialProviderSetUserArray )
                          {
                          *ppv = this;
                          reinterpret_cast<IUnknown*>(*ppv)->AddRef();
                          hr = S_OK;
                          }
                          else
                          {
                          *ppv = NULL;
                          hr = E_NOINTERFACE;
                          }
                          return hr;
                          }

                          ........ }; it is building with out errors .but when i execute dll logonui is crashing .how can implement two interfaces in one class please help me

                          H Offline
                          H Offline
                          H Pham
                          wrote on last edited by
                          #13

                          The issue might lie in this statement: *ppv = this; Because you use a C-cast to type void*, type information is lost. The pointer does not point to the correct virtual table of the interface that you want to return. Try the following instead:

                          STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
                          {
                          HRESULT hr;
                          if (IID_ICredentialProviderSetUserArray == riid)
                          {
                          *ppv = dynamic_cast<ICredentialProviderSetUserArray>( this );
                          reinterpret_cast<IUnknown*>(*ppv)->AddRef();
                          hr = S_OK;
                          }
                          else if (IID_IUnknown == riid ||
                          IID_ICredentialProvider == riid )
                          {
                          *ppv = dynamic_cast<ICredentialProvider>( this );
                          reinterpret_cast<IUnknown*>(*ppv)->AddRef();
                          hr = S_OK;
                          }
                          else
                          {
                          *ppv = NULL;
                          hr = E_NOINTERFACE;
                          }
                          return hr;
                          }

                          1 Reply Last reply
                          0
                          • V venkatesh52867

                            Hi, i have implemented two interfaces in class CSampleProvider : public ICredentialProvider,public ICredentialProviderSetUserArray { ....

                            STDMETHOD (QueryInterface)(REFIID riid, void** ppv)
                            {
                            HRESULT hr;
                            if (IID_IUnknown == riid ||
                            IID_ICredentialProvider == riid || IID_ICredentialProviderSetUserArray )
                            {
                            *ppv = this;
                            reinterpret_cast<IUnknown*>(*ppv)->AddRef();
                            hr = S_OK;
                            }
                            else
                            {
                            *ppv = NULL;
                            hr = E_NOINTERFACE;
                            }
                            return hr;
                            }

                            ........ }; it is building with out errors .but when i execute dll logonui is crashing .how can implement two interfaces in one class please help me

                            D Offline
                            D Offline
                            DriveByCoder
                            wrote on last edited by
                            #14

                            If you have a C++ class

                            class Z : public X, public Y
                            {
                            };

                            then you may be surprised to find that

                            this

                            is not a pointer to Y. Basic C++. But

                            static_cast(this)

                            is. You need a separate

                            if(riid == IID_...){...}

                            for each IID

                            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