Re: Problem passing SAFEARRAY of UDTs to Server
I'd make a guess here that you are using VC6. If that's the case,
you need to install a compatible version of the Platform SDK
which updates MIDL.EXE (the 2003 version is the last compatible
with VC6 IIRC). Make sure you integrate it with VC, and you
can also integrate its environment variables if you want (I always
do so).
As an unrelated note, why does everybody keep using typedefs
for structs... They are pointless, unless you happen to be programming
in C, and tend to bring their own issues in Automation interfaces
(though you are safe due to the way you've declared the typedef
with the same name as the struct - clearly showing the typedef
as unnecessary).
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Dazz Murphy" <dazz@dazzcraigmurphy.fsnet.co.uk> wrote in message
news:1157556912.476452.144070@p79g2000cwp.googlegroups.com...
I'm currently working on passing some data to a Server for processing
and i will need to pass an array of structures.
I have created a DLL INPROC Server to test this out, the IDL is as
follows:
import "oaidl.idl";
import "ocidl.idl";
typedef [uuid(E7524E2E-7C6E-4787-8B02-EEB81E639A41),
helpstring("Test Structure") ]
struct TACSTRUCT
{
short nID;
short nHdg;
float fLat;
float fLon;
float fHdg;
}TACSTRUCT;
[
object,
uuid(151F007A-5098-46F8-8BD5-D223EAA2E3BB),
dual,
helpstring("ITStructParserTest Interface"),
pointer_default(unique)
]
interface ITStructParserTest : IDispatch
{
[id(1), helpstring("method TParse")] HRESULT TParse([in]
SAFEARRAY(struct TACSTRUCT) *ppTArray);
};
[
uuid(EEBBA53C-4EE3-414F-A33B-D3B66D1D16F0),
version(1.0),
helpstring("TStructureParsing 1.0 Type Library")
]
library TSTRUCTUREPARSINGLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(5BCBEEF1-AC96-47FA-B95B-0724833BC03B),
helpstring("TStructParserTest Class")
]
coclass TStructParserTest
{
[default] interface ITStructParserTest;
};
struct TACSTRUCT;
};
This compiles but gives me the warning warning MIDL2039 : interface
does not conform to [oleautomation] attribute : [ Parameter 'ppTArray'
of Procedure 'TParse' ( Interface 'ITStructParserTest' ) ]
The remaining problem i have is the client software, courtesy of
several other google posts i have created the following:
CoInitialize(0);
HRESULT hr = CoCreateInstance(__uuidof(TStructParserTest), NULL,
CLSCTX_INPROC_SERVER, IID_ITStructParserTest,
reinterpret_cast<void**>(&m_ptrTest));
if(SUCCEEDED(hr))
{
SAFEARRAY *psa;
SAFEARRAYBOUND sab = {2, 0};
TACSTRUCT *pData;
IRecordInfo *pRI;
HRESULT hr;
hr = GetRecordInfoFromGuids(LIBID_TSTRUCTUREPARSINGLib, 1, 0, 0x409,
__uuidof(TACSTRUCT), &pRI);
psa = SafeArrayCreateEx(VT_RECORD, 1, &sab, pRI);
pRI->Release();
pRI = NULL;
hr = SafeArrayAccessData(psa, (void**)&pData);
hr = SafeArrayUnaccessData(psa);
m_ptrTest->TParse(&psa);
}
CoUninitialize();
This fails to compile with the following: error C2787: 'TACSTRUCT' : no
GUID has been associated with this object
This has been driving my nuts for a few days now and any help would be
appreciated.