How to pass UDTs(User Defined Type Array)
Author |
Message |
???F #1 / 4
|
 How to pass UDTs(User Defined Type Array)
I know the rules for passing UDTs between component and client. In IDL: 1. the user defined struct as follow: typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), helpstring("Component Information Struct") ] struct _COMPONENT_INFO{ [string] char *pstrAuthor; short sMajor; short sMinor; BSTR bstrName; }COMPONENT_INFO; 2. the interface which use the UDT: [ object, helpstring(...), dual, pointer_default(unique) ] Interface ... { [id(...)][helpstring(...)]...([out]?11??) 3. at server side to create the UDTs // { FB42007A-4D9F-4395-8E4C-8874CA9B9547 } DEFINE_GUID( GUID_Struct, 0xfb42007a, 0x4d9f, 0x4395, 0x8e, 0x4c, 0x88, 0x74, 0xca, 0x9b, 0x95, 0x47); ITypeLib* pTypelib; ITypeInfo* pTypeInfo=NULL; IRecordInfo* pRecordInfo=NULL; hr = LoadRegTypeLib(LIBID_CHAPTER4_SERVERLib, 1, 0, GetUserDefaultLCID(), &pTypelib); // ok hr = pTypelib->GetTypeInfoOfGuid( GUID_Struct, &pTypeInfo ); // get error why _ASSERT(SUCCEEDED(hr) && pTypeInfo); hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecordInfo); _ASSERT(SUCCEEDED(hr) && pRecordInfo); pTypeInfo->Release(); pTypelib->Release(); rgsabound[0].lLbound = 0; rgsabound[0].cElements = nSize; psaArray = SafeArrayCreateEx( VT_RECORD, 1, rgsabound, pRecordInfo ); Who can help me??? -- OICQ: 329170 ( ?D?3D? ) ICQ : 37175293 ( ?? ) ??3: http://www.*-*-*.com/ c/c++
|
Sun, 23 Nov 2003 06:25:54 GMT |
|
 |
Alexander Nickolo #2 / 4
|
 How to pass UDTs(User Defined Type Array)
As a first step - make your UDT Automation-compatible: typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), helpstring("Component Information Struct") ] struct COMPONENT_INFO { BSTR bstrAuthor; short sMajor; short sMinor; BSTR bstrName; Quote: } COMPONENT_INFO;
In IDL: SAFEARRAY(struct COMPONENT_INFO)* psa In code: hr = GetRecordInfoFromGuids(...); Also, see item 4 in the COM/ATL FAQ in my signature. -- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq =====================================
Quote: > I know the rules for passing UDTs between component and client. > In IDL: > 1. the user defined struct as follow: > typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), > helpstring("Component Information Struct") ] > struct _COMPONENT_INFO{ > [string] char *pstrAuthor; > short sMajor; > short sMinor; > BSTR bstrName; > }COMPONENT_INFO; > 2. the interface which use the UDT: > [ > object, > helpstring(...), > dual, > pointer_default(unique) > ] > Interface ... > { > [id(...)][helpstring(...)]...([out]?11??) > 3. at server side to create the UDTs > // { FB42007A-4D9F-4395-8E4C-8874CA9B9547 } > DEFINE_GUID( GUID_Struct, > 0xfb42007a, 0x4d9f, 0x4395, 0x8e, 0x4c, 0x88, 0x74, 0xca, 0x9b, 0x95, 0x47); > ITypeLib* pTypelib; > ITypeInfo* pTypeInfo=NULL; > IRecordInfo* pRecordInfo=NULL; > hr = LoadRegTypeLib(LIBID_CHAPTER4_SERVERLib, 1, 0, GetUserDefaultLCID(), > &pTypelib); // ok > hr = pTypelib->GetTypeInfoOfGuid( GUID_Struct, &pTypeInfo ); > // get error why > _ASSERT(SUCCEEDED(hr) && pTypeInfo); > hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecordInfo); > _ASSERT(SUCCEEDED(hr) && pRecordInfo); > pTypeInfo->Release(); > pTypelib->Release(); > rgsabound[0].lLbound = 0; > rgsabound[0].cElements = nSize; > psaArray = SafeArrayCreateEx( VT_RECORD, 1, rgsabound, pRecordInfo ); > Who can help me??? > -- > OICQ: 329170 ( ?D?3D? ) > ICQ : 37175293 ( ?? ) > ??3: http://www.ccw.com.cn c/c++
|
Mon, 24 Nov 2003 08:25:28 GMT |
|
 |
???F #3 / 4
|
 How to pass UDTs(User Defined Type Array)
The biggest problem is it returns error that tells me can't find the object, here is the idl: //IComponentInfo typedef [uuid( 57B92B3C-91A2-48f5-861D-C6C125EAC867 ), helpstring( "IComponent's Component Info Struct" ) ] struct _COMPONENT_INFO{ [string] char *pstrAuthor; short sMajor; short sMinor; BSTR bstrName; }COMPONENT_INFO; [ object, uuid(02753E92-9CD5-4bff-A0EE-9FF967CBD467), helpstring("IComponentInfo Interface"), dual, pointer_default(unique) ] interface IComponentInfo:IDispatch { [id(1),helpstring("method get_Info")] HRESULT get_Info( [in]UINT nSize, [out, retval]VARIANT* pv ); [id(2),helpstring("method get_Name")] HRESULT get_Name( [out, retval]BSTR* bstrName ); [propget, id(3), helpstring("property ComponentInfo")] HRESULT ComponentInfo([out, retval] COMPONENT_INFO *pVal); }; [ uuid(65F273FB-C6B9-42DD-B9FE-A3C43FE205F9), version(1.0), helpstring("Chapter4_Server 1.0 Type Library") ] library CHAPTER4_SERVERLib { importlib("stdole32.tlb"); importlib("stdole2.tlb"); [ uuid(EB49A0EB-884A-4DB6-BD0B-278981F902B5), helpstring("Math Class") ] coclass Math { [default] interface IMath; interface IComponentInfo; interface IAdvancedMath; interface IMath2; }; }; -- OICQ: 329170 ( ?D?3D? ) ICQ : 37175293 ( ?? ) ??3: http://www.ccw.com.cn c/c++
Quote: > As a first step - make your UDT Automation-compatible: > typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), > helpstring("Component Information Struct") ] > struct COMPONENT_INFO { > BSTR bstrAuthor; > short sMajor; > short sMinor; > BSTR bstrName; > } COMPONENT_INFO; > In IDL: > SAFEARRAY(struct COMPONENT_INFO)* psa > In code: > hr = GetRecordInfoFromGuids(...); > Also, see item 4 in the COM/ATL FAQ in my signature. > -- > ===================================== > Alexander Nickolov > Microsoft MVP [VC], MCSD
> MVP VC FAQ: http://www.mvps.org/vcfaq > =====================================
> > I know the rules for passing UDTs between component and client. > > In IDL: > > 1. the user defined struct as follow: > > typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), > > helpstring("Component Information Struct") ] > > struct _COMPONENT_INFO{ > > [string] char *pstrAuthor; > > short sMajor; > > short sMinor; > > BSTR bstrName; > > }COMPONENT_INFO; > > 2. the interface which use the UDT: > > [ > > object, > > helpstring(...), > > dual, > > pointer_default(unique) > > ] > > Interface ... > > { > > [id(...)][helpstring(...)]...([out]?11??) > > 3. at server side to create the UDTs > > // { FB42007A-4D9F-4395-8E4C-8874CA9B9547 } > > DEFINE_GUID( GUID_Struct, > > 0xfb42007a, 0x4d9f, 0x4395, 0x8e, 0x4c, 0x88, 0x74, 0xca, 0x9b, 0x95, > 0x47); > > ITypeLib* pTypelib; > > ITypeInfo* pTypeInfo=NULL; > > IRecordInfo* pRecordInfo=NULL; > > hr = LoadRegTypeLib(LIBID_CHAPTER4_SERVERLib, 1, 0,
GetUserDefaultLCID(), Quote: > > &pTypelib); // ok > > hr = pTypelib->GetTypeInfoOfGuid( GUID_Struct, &pTypeInfo ); > > // get error why > > _ASSERT(SUCCEEDED(hr) && pTypeInfo); > > hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecordInfo); > > _ASSERT(SUCCEEDED(hr) && pRecordInfo); > > pTypeInfo->Release(); > > pTypelib->Release(); > > rgsabound[0].lLbound = 0; > > rgsabound[0].cElements = nSize; > > psaArray = SafeArrayCreateEx( VT_RECORD, 1, rgsabound, pRecordInfo ); > > Who can help me??? > > -- > > OICQ: 329170 ( ?D?3D? ) > > ICQ : 37175293 ( ?? ) > > ??3: http://www.ccw.com.cn c/c++
|
Tue, 25 Nov 2003 05:51:11 GMT |
|
 |
Alexander Nickolo #4 / 4
|
 How to pass UDTs(User Defined Type Array)
Do you get a warning from MIDL that it is not Automation-compatible? You have to make it disappear first... Hint - UINT is a _very_ new Automation type - better use long instead. -- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD
MVP VC FAQ: http://www.mvps.org/vcfaq =====================================
Quote: > The biggest problem is it returns error that tells me can't find the object, > here is the idl: > //IComponentInfo > typedef [uuid( 57B92B3C-91A2-48f5-861D-C6C125EAC867 ), helpstring( > "IComponent's Component Info Struct" ) ] > struct _COMPONENT_INFO{ > [string] char *pstrAuthor; > short sMajor; > short sMinor; > BSTR bstrName; > }COMPONENT_INFO; > [ > object, > uuid(02753E92-9CD5-4bff-A0EE-9FF967CBD467), > helpstring("IComponentInfo Interface"), > dual, > pointer_default(unique) > ] > interface IComponentInfo:IDispatch > { > [id(1),helpstring("method get_Info")] HRESULT get_Info( [in]UINT nSize, > [out, retval]VARIANT* pv ); > [id(2),helpstring("method get_Name")] HRESULT get_Name( [out, retval]BSTR* > bstrName ); > [propget, id(3), helpstring("property ComponentInfo")] HRESULT > ComponentInfo([out, retval] COMPONENT_INFO *pVal); > }; > [ > uuid(65F273FB-C6B9-42DD-B9FE-A3C43FE205F9), > version(1.0), > helpstring("Chapter4_Server 1.0 Type Library") > ] > library CHAPTER4_SERVERLib > { > importlib("stdole32.tlb"); > importlib("stdole2.tlb"); > [ > uuid(EB49A0EB-884A-4DB6-BD0B-278981F902B5), > helpstring("Math Class") > ] > coclass Math > { > [default] interface IMath; > interface IComponentInfo; > interface IAdvancedMath; > interface IMath2; > }; > }; > -- > OICQ: 329170 ( ?D?3D? ) > ICQ : 37175293 ( ?? ) > ??3: http://www.ccw.com.cn c/c++
> > As a first step - make your UDT Automation-compatible: > > typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), > > helpstring("Component Information Struct") ] > > struct COMPONENT_INFO { > > BSTR bstrAuthor; > > short sMajor; > > short sMinor; > > BSTR bstrName; > > } COMPONENT_INFO; > > In IDL: > > SAFEARRAY(struct COMPONENT_INFO)* psa > > In code: > > hr = GetRecordInfoFromGuids(...); > > Also, see item 4 in the COM/ATL FAQ in my signature. > > -- > > ===================================== > > Alexander Nickolov > > Microsoft MVP [VC], MCSD
> > MVP VC FAQ: http://www.mvps.org/vcfaq > > =====================================
> > > I know the rules for passing UDTs between component and client. > > > In IDL: > > > 1. the user defined struct as follow: > > > typedef [ uuid( FB42007A-4D9F-4395-8E4C-8874CA9B9547 ), > > > helpstring("Component Information Struct") ] > > > struct _COMPONENT_INFO{ > > > [string] char *pstrAuthor; > > > short sMajor; > > > short sMinor; > > > BSTR bstrName; > > > }COMPONENT_INFO; > > > 2. the interface which use the UDT: > > > [ > > > object, > > > helpstring(...), > > > dual, > > > pointer_default(unique) > > > ] > > > Interface ... > > > { > > > [id(...)][helpstring(...)]...([out]?11??) > > > 3. at server side to create the UDTs > > > // { FB42007A-4D9F-4395-8E4C-8874CA9B9547 } > > > DEFINE_GUID( GUID_Struct, > > > 0xfb42007a, 0x4d9f, 0x4395, 0x8e, 0x4c, 0x88, 0x74, 0xca, 0x9b, 0x95, > > 0x47); > > > ITypeLib* pTypelib; > > > ITypeInfo* pTypeInfo=NULL; > > > IRecordInfo* pRecordInfo=NULL; > > > hr = LoadRegTypeLib(LIBID_CHAPTER4_SERVERLib, 1, 0, > GetUserDefaultLCID(), > > > &pTypelib); // ok > > > hr = pTypelib->GetTypeInfoOfGuid( GUID_Struct, &pTypeInfo ); > > > // get error why > > > _ASSERT(SUCCEEDED(hr) && pTypeInfo); > > > hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecordInfo); > > > _ASSERT(SUCCEEDED(hr) && pRecordInfo); > > > pTypeInfo->Release(); > > > pTypelib->Release(); > > > rgsabound[0].lLbound = 0; > > > rgsabound[0].cElements = nSize; > > > psaArray = SafeArrayCreateEx( VT_RECORD, 1, rgsabound, pRecordInfo ); > > > Who can help me??? > > > -- > > > OICQ: 329170 ( ?D?3D? ) > > > ICQ : 37175293 ( ?? ) > > > ??3: http://www.ccw.com.cn c/c++
|
Wed, 26 Nov 2003 00:30:32 GMT |
|
|
|