Get ProgID or CLSID if i have only pointer to some IDispatch interface
-
How i can get ProgID or CLSID if i have only pointer to some IDispatch interface. For example: CComPtr< ISome > spSome; I was trying to do the next: CComPtr spTypeInfo; hr = m_spSome->GetTypeInfo( 100, LOCALE_SYSTEM_DEFAULT, &spTypeInfo ); if( FAILED( hr = PrepareFuncInfo() ) ) { return hr; } TYPEATTR *pattr = NULL; hr = spTypeInfo->GetTypeAttr( &pattr ); if( FAILED( hr = PrepareFuncInfo() ) ) { spTypeInfo.Release(); return hr; } CComPtr spTypeInfo2; HREFTYPE hrType = 0; while( SUCCEEDED( hr = spTypeInfo->GetRefTypeInfo( hrType, &spTypeInfo2 ) ) ) { TYPEATTR *pattr2 = NULL; hr = spTypeInfo2->GetTypeAttr( &pattr2 ); if( FAILED( hr = PrepareFuncInfo() ) ) { spTypeInfo2.Release(); spTypeInfo.Release(); return hr; } if( pattr2->typekind == TKIND_COCLASS ) { BSTR bsCLSID; ProgIDFromCLSID( pattr2->guid, &bsCLSID ); m_bsProgIDName = bsCLSID; spTypeInfo2.Release(); spTypeInfo.Release(); return S_OK; } hrType++; } But it doesn't work in variant, when i have in type lib more then 1 coclass :) I can to do this using type lib, but i want to find another way for solving this problem. If it's exists - please tell? how i can to do this :) Because i so tired with this...... :)
ISQ 469907496
-
How i can get ProgID or CLSID if i have only pointer to some IDispatch interface. For example: CComPtr< ISome > spSome; I was trying to do the next: CComPtr spTypeInfo; hr = m_spSome->GetTypeInfo( 100, LOCALE_SYSTEM_DEFAULT, &spTypeInfo ); if( FAILED( hr = PrepareFuncInfo() ) ) { return hr; } TYPEATTR *pattr = NULL; hr = spTypeInfo->GetTypeAttr( &pattr ); if( FAILED( hr = PrepareFuncInfo() ) ) { spTypeInfo.Release(); return hr; } CComPtr spTypeInfo2; HREFTYPE hrType = 0; while( SUCCEEDED( hr = spTypeInfo->GetRefTypeInfo( hrType, &spTypeInfo2 ) ) ) { TYPEATTR *pattr2 = NULL; hr = spTypeInfo2->GetTypeAttr( &pattr2 ); if( FAILED( hr = PrepareFuncInfo() ) ) { spTypeInfo2.Release(); spTypeInfo.Release(); return hr; } if( pattr2->typekind == TKIND_COCLASS ) { BSTR bsCLSID; ProgIDFromCLSID( pattr2->guid, &bsCLSID ); m_bsProgIDName = bsCLSID; spTypeInfo2.Release(); spTypeInfo.Release(); return S_OK; } hrType++; } But it doesn't work in variant, when i have in type lib more then 1 coclass :) I can to do this using type lib, but i want to find another way for solving this problem. If it's exists - please tell? how i can to do this :) Because i so tired with this...... :)
ISQ 469907496
Use
QueryInterface
to discover whether the class implementsIProvideClassInfo
. From there you can discover the type information of the class.
DoEvents
: Generating unexpected recursion since 1991 -
Use
QueryInterface
to discover whether the class implementsIProvideClassInfo
. From there you can discover the type information of the class.
DoEvents
: Generating unexpected recursion since 1991Thanks, but not all objects implement this interface. I need reliable method wich will be suitable for all objects!
ISQ 469907496
-
Thanks, but not all objects implement this interface. I need reliable method wich will be suitable for all objects!
ISQ 469907496
vippavlo wrote:
Thanks, but not all objects implement this interface. I need reliable method wich will be suitable for all objects!
You cannot do that! :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Thanks, but not all objects implement this interface. I need reliable method wich will be suitable for all objects!
ISQ 469907496
-
Why do you need this functionality? If you can share the problem you are trying to solve, folks here can possibly tell you a better solution.
Sohail
it's very long story... :) i want to save progID in XMLDOM attribute when i have only pointer to interface and than create object using this progid from XMLDOM file.
ISQ 469907496
-
it's very long story... :) i want to save progID in XMLDOM attribute when i have only pointer to interface and than create object using this progid from XMLDOM file.
ISQ 469907496
vippavlo wrote:
it's very long story...
I'll leave it for tomorrow, heading home in few minutes :)
vippavlo wrote:
i want to save progID in XMLDOM attribute when i have only pointer to interface and than create object using this progid from XMLDOM file.
What about COM DLLs that support only DispInterface? Is this so called pointer passed to you by external application or it's created in your own application?
Sohail
-
vippavlo wrote:
it's very long story...
I'll leave it for tomorrow, heading home in few minutes :)
vippavlo wrote:
i want to save progID in XMLDOM attribute when i have only pointer to interface and than create object using this progid from XMLDOM file.
What about COM DLLs that support only DispInterface? Is this so called pointer passed to you by external application or it's created in your own application?
Sohail
/*What about COM DLLs that support only DispInterface? */ What you mean??
ISQ 469907496
-
/*What about COM DLLs that support only DispInterface? */ What you mean??
ISQ 469907496
-
Sorry, just went off track :) I was talking about Dispatch Interfaces as in http://www.microsoft.com/msj/0898/idl/idl.aspx[^]
Sohail
It's you sorry me, maybe i said somthing wrong? because i dont know english perfect - my grammar is bad :) I'm know perfect what is mean "IDispatch" :)))) I don't understand your question, what you whant to tolk with this words about DDL's - what's problem with DDL's?????? I was not read you last sentence :) sory :) .... It's a component for SDK - it save program settings to XML file and one of parameters can to be an interface and i put into XML properties of this object and want to put ProgID for in future create object using this ProgID. Now i have this code and it work without some p'roblems, but if some other compiler, VisualBasic for example, generate type lib with another way.... it will not be working..... Where m_spObj - its smart pointer CCOmPtr, for example... :) CComPtr spTypeInfo; UINT uiCount = 0; GUID guidOfInterface; hr = m_spObj->GetTypeInfo( 100, LOCALE_SYSTEM_DEFAULT, &spTypeInfo ); TYPEATTR *pattr1 = NULL; hr = spTypeInfo->GetTypeAttr( &pattr1 ); guidOfInterface = pattr1->guid; CComPtr< ITypeLib > spTypeLib; hr = spTypeInfo->GetContainingTypeLib( &spTypeLib, &uiCount ); uiCount = spTypeLib->GetTypeInfoCount(); CLSID clsidOfCoclass; for( UINT i = 0; i < uiCount; i++ ) { CComPtr< ITypeInfo > spTI; hr = spTypeLib->GetTypeInfo( i, &spTI ); TYPEATTR *pattr = NULL; hr = spTI->GetTypeAttr( &pattr ); if( pattr->typekind == TKIND_COCLASS ) { clsidOfCoclass = pattr->guid; } if( pattr->typekind == TKIND_DISPATCH ) { if( guidOfInterface == pattr->guid ) { CComBSTR bsCLSID; ProgIDFromCLSID( clsidOfCoclass, &bsCLSID ); m_bsProgIDName = bsCLSID.Detach(); spTI.Release(); spTypeLib.Release(); spTypeInfo.Release(); return S_OK; } } spTI.Release(); } spTypeLib.Release(); spTypeInfo.Release(); return hr;
ISQ 469907496
-
It's you sorry me, maybe i said somthing wrong? because i dont know english perfect - my grammar is bad :) I'm know perfect what is mean "IDispatch" :)))) I don't understand your question, what you whant to tolk with this words about DDL's - what's problem with DDL's?????? I was not read you last sentence :) sory :) .... It's a component for SDK - it save program settings to XML file and one of parameters can to be an interface and i put into XML properties of this object and want to put ProgID for in future create object using this ProgID. Now i have this code and it work without some p'roblems, but if some other compiler, VisualBasic for example, generate type lib with another way.... it will not be working..... Where m_spObj - its smart pointer CCOmPtr, for example... :) CComPtr spTypeInfo; UINT uiCount = 0; GUID guidOfInterface; hr = m_spObj->GetTypeInfo( 100, LOCALE_SYSTEM_DEFAULT, &spTypeInfo ); TYPEATTR *pattr1 = NULL; hr = spTypeInfo->GetTypeAttr( &pattr1 ); guidOfInterface = pattr1->guid; CComPtr< ITypeLib > spTypeLib; hr = spTypeInfo->GetContainingTypeLib( &spTypeLib, &uiCount ); uiCount = spTypeLib->GetTypeInfoCount(); CLSID clsidOfCoclass; for( UINT i = 0; i < uiCount; i++ ) { CComPtr< ITypeInfo > spTI; hr = spTypeLib->GetTypeInfo( i, &spTI ); TYPEATTR *pattr = NULL; hr = spTI->GetTypeAttr( &pattr ); if( pattr->typekind == TKIND_COCLASS ) { clsidOfCoclass = pattr->guid; } if( pattr->typekind == TKIND_DISPATCH ) { if( guidOfInterface == pattr->guid ) { CComBSTR bsCLSID; ProgIDFromCLSID( clsidOfCoclass, &bsCLSID ); m_bsProgIDName = bsCLSID.Detach(); spTI.Release(); spTypeLib.Release(); spTypeInfo.Release(); return S_OK; } } spTI.Release(); } spTypeLib.Release(); spTypeInfo.Release(); return hr;
ISQ 469907496
vippavlo wrote:
It's a component for SDK - it save program settings to XML file and one of parameters can to be an interface and i put into XML properties of this object and want to put ProgID for in future create object using this ProgID. Now i have this code and it work without some p'roblems, but if some other compiler, VisualBasic for example, generate type lib with another way.... it will not be working.....
I think you should be allowed to insist that such objects support an appropriate IPersist interface. I recall that the plain IPersist interface has just one method which returns the class ID. The reason that you can't use the type info for this is because there can be any number of COCLASSes in the type library that implement the interface. There is no provision for doing what you want in that case. Nathan