Implementation two interfaces in one class
-
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
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
-
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
-
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
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.
-
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.
-
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.
-
if (IID_IUnknown == riid ||
IID_ICredentialProvider == riid ||
IID_ICredentialProviderSetUserArray)
{Do you see something missing here?
Use the best guess
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
-
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
-
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.
-
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 :)
-
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 :)
-
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
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;
} -
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
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