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

Using SAFEARRAY with ATL 7

74 views
Skip to first unread message

Robert Greig

unread,
Jun 23, 2003, 7:24:37 AM6/23/03
to
Hi,

I am using ATL 7 (with attributes) and I have been
passing back a SAFEARRAY wrapped in a VARIANT from a
property get method. This works fine.

I am wanting to return a plain SAFEARRAY, i.e. not wrap
it up in a VARIANT.

However, I cannot figure out the syntax to get it to put
SAFEARRAY(BSTR*) in the idl file.

For example, I currently have the method in the interface:

[id(4), propget]
HRESULT TheAnalysts([out, retval] VARIANT* pAnalysts);

Changing it to this doesn't work:
[id(4), propget]
HRESULT TheAnalysts([out, retval] SAFEARRAY** ppAnalysts);

midl fails to compile the IDL. This makes sense since the
generated IDL doesn't have the correct SAFEARRRAY
(typename) syntax. Putting in SAFEARRAY(BSTR*) for
example means it doesn't compile due to syntax errors
(again understandably).

I've searched for an attribute to make this work but I
couldn't find anything.

Any ideas?

Thanks,

Robert Greig

Alex Shirshov

unread,
Jun 23, 2003, 8:00:56 AM6/23/03
to
SAFEARRAY(BSTR)*

--
Sorry for bad English.

"Robert Greig" <robert....@jpmorgan.com> wrote in message
news:041d01c3397a$0801e0c0$a001...@phx.gbl...

Robert Greig

unread,
Jun 23, 2003, 9:16:54 AM6/23/03
to
You would think this is the correct solution but this
does not compile:

error C2143: syntax error : missing ',' before '*'

You'd expect to put that in the IDL but with ATL 7.0 with
attributes you put everything directly into the C++.

Any other ideas?

Thanks,

Robert

>.
>

Brian Muth

unread,
Jun 23, 2003, 12:33:42 PM6/23/03
to
[propget, helpstring("property TheAnalysts")] HRESULT TheAnalysts([out,
retval] SAFEARRAY(BSTR)* pVal);

compiles fine for me.

Brian


Robert Greig

unread,
Jun 23, 2003, 1:59:18 PM6/23/03
to

Hmm. I cannot understand what I am doing wrong.

Here is my complete interface (in a file on its own):

#include "stdafx.h"

[
object,
uuid("2D1420B6-F66F-4969-A094-8542A3198682"),
dual,
helpstring("IKey Interface"),
pointer_default(unique)
]
__interface IKey : IDispatch
{
[id(1), propget]
HRESULT Id([out, retval] SAFEARRAY(BSTR) *pId);
};

When I compile it I get these errors:

error C2143: syntax error : missing ',' before '*'

error C3763: 'SAFEARRAY': 'retval' and 'out' can only
appear on a data-pointer type
error C3763: 'SAFEARRAY': 'retval' and 'out' can only
appear on a data-pointer type

Can you spot what is wrong? NB - not sure if it matters
but I'm using VC++ 2003.

Thanks,

Robert

Alexander Nickolov

unread,
Jun 23, 2003, 2:08:07 PM6/23/03
to
You are missing the satype attribute. Read its reference in MSDN
Library:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcattrib/html/vcrefsatype.asp

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Robert Greig" <robert....@jpmorgan.dot.com> wrote in message news:07ef01c33989$b786bf70$a601...@phx.gbl...

Brian Muth

unread,
Jun 23, 2003, 2:14:24 PM6/23/03
to
I don't use attributed interfaces, and I suspect this is where the problem
arises. What does the generated IDL look like?


"Robert Greig" <robert....@jpmorgan.dot.com> wrote in message

news:03be01c339b1$2a848b70$a101...@phx.gbl...

Brian Muth

unread,
Jun 23, 2003, 2:15:47 PM6/23/03
to
Gosh, Alexander, I didn't think you used attributed interfaces either!


Alexander Nickolov

unread,
Jun 23, 2003, 2:26:40 PM6/23/03
to
No, I don't, I use VC 6.0 :). I just happen to have seen a mention of it
some time earlier in this NG, or something... Then it was a simple
matter of locating it (online, since I don't have the appropriate MSDN
installed locally either...).

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Brian Muth" <bm...@straightthroughnospam.com> wrote in message news:e8%235rNbO...@TK2MSFTNGP10.phx.gbl...

0 new messages