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

Implementing IEnumXXXX

19 views
Skip to first unread message

Udi Pladott

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
Hi,

I want to define my own flavor of IEnumXXXX. Why do I really need to
define two versions of Next() ? Wouldn't the fully remotable version work
just as well when called in the same apartment?

Thanks.

Udi Pladott
NetinTouch.com
--------------------------
u...@netintouch.com

Alexander Nickolov

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
It requires some additional code to deal with the possibility of a NULL
pointer for the returned count. Hence the two versions are required so
such code can be inserted in the proxy/stub DLL source (by you).

--
===============================
Alexander Nickolov
Panasonic Technologies Inc.
Speech Technology Laboratory
email: agnic...@geocities.com
===============================

Udi Pladott wrote in message ...

Udi Pladott

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to

Alexander Nickolov wrote in message ...

>It requires some additional code to deal with the possibility of a NULL
>pointer for the returned count. Hence the two versions are required so
>such code can be inserted in the proxy/stub DLL source (by you).
>

So should I just add another file to the dependency list in my
MYPROJps.mk makefile and put that code in the new file? How shoud I handle
this NULL pointer?

Thanks.
Udi.

Alexander Nickolov

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
To be precise, I've only read this in a book, but it makes sense.
Perhaps you should fail the call outright if the pointer is NULL
and the asked count is more than one. In the special case of
1 element you should call the remote method with the address
of a stack variable in place of the NULL parameter and forget
it after the call returns (since the client doesn't want it). I'm not
the guru on standard marshaling. There are more hardcore guys
in this newsgroup...

As for the code you should write - see the help on 'call_as' in the
MIDL documentation. If it isn't clear - MIDL just relies that you'll
provide those two functions so the link step will fail without them.
You simply add another .c file to the proxy/stub project.

Peter Partch

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
Alexander;

This will not work.

The failure will occur in the interface proxy. The proxy (generated by MIDL)
will check for NULL for toplevel outbound pointers and throw an exception
(caught by the proxy witch will return a failure HRESULT). You server will
never get the Next call.

You add local/call_as pair to your interface declaration of Next in IDL.
This will require you to add proxy and stub method "hooks" where you can fix
up the NULL as the client makes the inbound call. Here is some source for
these hooks:

Given a custom enumerator called IEnumShopItems and the Next (in IDL)
declared as:
[local]
HRESULT Next(
[in] ULONG celt,
[out, size_is(celt), length_is(*pCeltFetched)] SHOPITEM*
rgelt,
[out] ULONG * pCeltFetched
);

[call_as(Next)]
HRESULT RemoteNext(
[in] ULONG celt,
[out, size_is(celt), length_is(*pCeltFetched)] SHOPITEM*
rgelt,
[out] ULONG * pCeltFetched
);

Then the hooks that need to be added to the proxy/stub are as follows:
/* [local] */ HRESULT STDMETHODCALLTYPE
umShopItems_Next_Proxy(
IEnumShopItems __RPC_FAR * This,
/* [in] */ ULONG celt,
/* [length_is][size_is][out] */ SHOPITEM __RPC_FAR *rgelt,
/* [out] */ ULONG __RPC_FAR *pCeltFetched)
{
if (!pCeltFetched)
if (celt != 1)
return E_INVALIDARG;

ULONG cnt = 0;

HRESULT hr = IEnumShopItems_RemoteNext_Proxy(This,celt,rgelt,&cnt);

if (pCeltFetched)
*pCeltFetched = cnt;

return hr;
}


/* [call_as] */ HRESULT STDMETHODCALLTYPE IEnumShopItems_Next_Stub(
IEnumShopItems __RPC_FAR * This,
/* [in] */ ULONG celt,
/* [length_is][size_is][out] */ SHOPITEM __RPC_FAR *rgelt,
/* [out] */ ULONG __RPC_FAR *pCeltFetched)
{
return This->Next(celt,rgelt,pCeltFetched);
}

Peter Partch

Alexander Nickolov

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
Well, you pretty much confirmed what I wrote. From the question
it was clear that I'm talking about the local-to-call_as functions.
You simply provided the actual implementation.

--
===============================
Alexander Nickolov
Panasonic Technologies Inc.
Speech Technology Laboratory
email: agnic...@geocities.com
===============================

Peter Partch wrote in message ...

Peter Partch

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
Sorry, my reference to "this will not work" was in your suggestion of
checking the last parameter in the Next implementation.

without this local/call_as hook and when calling via a proxy the last
parameter will never be NULL therefore the check will do little good for
across apartment calls.

After re-reading your posting, maybe I think that my terse remark was not
warranted.

Peter

Alexander Nickolov

unread,
Jun 9, 1999, 3:00:00 AM6/9/99
to
Well, I didn't say it explicitly, which is my fault :).

For anybody, if there is still confusion, all my posts regarded the
implementation of the local-to-call_as function on the proxy
(local) side of the conversion. All thanks go to Mr Partch who
provided actual working source code.

Udi Pladott

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to
Thanks a lot to both of you.

I implemented the proxy / stub code as both of you suggested, but now the
method I have in my type library is RemoteNext(). How can I have only Next()
in there instead, and still get the right version called depending on
whether I'm in the same apartment or not?


Udi.


Alexander Nickolov wrote in message <#XToVzss#GA.195@cppssbbsa03>...

Alexander Nickolov

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to
Very simple - don't put it in the type library at all! Follow the
Microsoft's
example...

Udi Pladott

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to

Alexander Nickolov wrote in message ...
>Very simple - don't put it in the type library at all! Follow the
>Microsoft's
>example...
>


But I need my clients to use it .....

Alexander Nickolov

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to
Your clients don't include VB or any scripting environments, so why
bother? Simply distribute the IDL and optionally the generated header
file (Microsoft does it this way). You must distribute the proxy/stub
DLL though. You don't have to include a library block at all.

Udi Pladott

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to

Alexander Nickolov wrote in message ...
>Your clients don't include VB or any scripting environments, so why
>bother? Simply distribute the IDL and optionally the generated header
>file (Microsoft does it this way). You must distribute the proxy/stub
>DLL though. You don't have to include a library block at all.
>

My client is written in Delphi which does work with vtbl interfaces but
gets it all from the TLB.

Udi.

>--
>===============================
>Alexander Nickolov
>Panasonic Technologies Inc.

Alexander Nickolov

unread,
Jun 10, 1999, 3:00:00 AM6/10/99
to
Hmm, that's a point. Can you create the Delphi definition by hand?
The standard interfaces must have done their way into Delphi
somehow... This is not a general recommendation - only for this
case. Else, I'm not expert on type libraries - see if the 'hidden'
attribute helps...

Girish Bharadwaj [mvp]

unread,
Jun 11, 1999, 3:00:00 AM6/11/99
to
There is one way of doing that. Bracket the [local] and [call_as] stuff in a
# define. something like

#ifndef _TYPELIB_BUILD
[local] Next();
[call_as(Next)]RemoteNext();
#else
Next();
#endif
Now, rebuild your idl twice once with _TYPELIB_BUILD and once without it. The
one without the _TYPELIB_BUILD will generate the _p.c and _i.c stuff which you
can build to get the proxy/stub. and the typelib generated when that is
defined can be distributed with the component. Now, you are happy and so are
your delphi customers <g>.


In article <eRnTad5s#GA....@cppssbbsa02.microsoft.com>, "Alexander Nickolov"

<agnic...@geocities.com> wrote:
>Hmm, that's a point. Can you create the Delphi definition by hand?
>The standard interfaces must have done their way into Delphi
>somehow... This is not a general recommendation - only for this
>case. Else, I'm not expert on type libraries - see if the 'hidden'
>attribute helps...
>

----
Girish Bharadwaj B.V [vc++/mvp]
Please post Questions in the newsgroups.
Do not mail them to me directly.
Thank you.
---

0 new messages