Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SAFEARRAYS with COM

177 views
Skip to first unread message

Michel Voide

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
Hi -

I'm trying to use an in/out SAFEARRAY with COM and VC++ 5, but it doesn't
work very fine :

First, when I add the following definition to my dispatch interface IDL
[id(10), helpstring("method testSafeArrayInt")] HRESULT
testSafeArrayInt([in, out] SAFEARRAY(int) theArray, [in] int increment);

the wizard adds the following to the c++ file :

STDMETHODIMP SimpleTest1::testSafeArrayInt(SAFEARRAY ( int ) theArray,
int increment)
which of course is not understood by the c++ compiler .....

when I correct this to

STDMETHODIMP SimpleTest1::testSafeArrayInt(SAFEARRAY /*( int )*/ theArray,
int increment)

it says following :

C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(162) : error C2259:
'CComObject<class SimpleTest1>' : cannot instantiate abstract class due to
following members:
C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(162) : warning C4259:
'long __stdcall ISimpleTest1::testSafeArrayInt(struct tagSAFEARRAY *,int)' :
pure virtual function was not defined
C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(162) : error C2259:
'CComObject<class SimpleTest1>' : cannot instantiate abstract class due to
following members:
C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(162) : warning C4259:
'long __stdcall ISimpleTest1::testSafeArrayInt(struct tagSAFEARRAY *,int)' :
pure virtual function was not defined
C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(874) : error C2259:
'CComContainedObject<class SimpleTest1>' : cannot instantiate abstract class
due to following members:
C:\Program Files\DevStudio\VC\ATL\include\atlcom.h(874) : warning C4259:
'long __stdcall ISimpleTest1::testSafeArrayInt(struct tagSAFEARRAY *,int)' :
pure virtual function was not defined

and if I make the final correction :

STDMETHODIMP SimpleTest1::testSafeArrayInt(SAFEARRAY* /*( int )*/ theArray,
int increment)
my server compiles, but returns a "type mismatch" error when I call the
function via COM, which is
normal, as this is not what I defined in the IDL !

Does anybody have a solution to this ?

Please help !


Scott Rabon

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
You might want to try using a VARIANT* type parameter, instead of the
SAFEARRAY parameter. And since you are using a dispatch interface, the
VARIANT type will be compatible with VB clients. So your function
declaration in the idl would look like:
HRESULT tesstSafeArrayInt( [in, out]VARIANT* theArray, [in]int increment);

Then access the SAFEARRAY in the VARIANT structure in your function.

Scott

Michel Voide wrote in message <36656...@epflnews.epfl.ch>...

newgroups

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
If you take this approach, you can find some text and a sample ATL project
with a VB6 client here:
http://www.arpsolutions.demon.co.uk/atl/atl_faq_001.htm

Scott Rabon wrote in message <8yf92.671$vR3....@news.ntplx.net>...

Ben Hutchings

unread,
Dec 3, 1998, 3:00:00 AM12/3/98
to
Scott Rabon (sc...@eaglesol.com) wrote:
: You might want to try using a VARIANT* type parameter, instead of the

: SAFEARRAY parameter. And since you are using a dispatch interface, the
: VARIANT type will be compatible with VB clients. So your function
: declaration in the idl would look like:
: HRESULT tesstSafeArrayInt( [in, out]VARIANT* theArray, [in]int increment);

: Then access the SAFEARRAY in the VARIANT structure in your function.

<snip>

Don't forget to check that

variant.vt == (VT_ARRAY | VT_I4)
----- (or whatever the array should contain)

before accessing the array, though.

--
Any opinions expressed are my own and not necessarily those of Laser-Scan.

Michel Voide

unread,
Dec 3, 1998, 3:00:00 AM12/3/98
to
Thank you all - it all works now....

But, just for curiosity ... I've read in some DCOM book that to send
directly a safearray, you
should use the following syntax in the IDL :
[in, out] SAFEARRAY(int) *myVar

Do you know if it is possible this way, or is it mandatory to use a VARIANT
type ? It seems at least that
the VC5 has a problem with this (refer to my previous message for more
infos....)

Thanks again ....

mvo

0 new messages