I'm attempting a managed implementation of a COM interface, which
enumerates structures... (The interface is ISyncMgrEnumItems, defined
in MobSync.idl, for anyone who wants to play along.)

Here's the relevant snippet of IDL:

    HRESULT Next(
        [in] ULONG celt,
        [out, size_is(celt), length_is(*pceltFetched)]
        LPSYNCMGRITEM rgelt,
        [out] ULONG *pceltFetched);

SYNCMGRITEM is a (fairly hefty) struct composed of simple, blittable
types, including an in-place character array:

    typedef struct _tagSYNCMGRITEM {
        DWORD       cbSize;
        DWORD       dwFlags;
        SYNCMGRITEMID  ItemID;
        DWORD       dwItemState;
        HICON       hIcon;
        WCHAR       wszItemName[128];
        FILETIME    ftLastUpdate;
    } SYNCMGRITEM, *LPSYNCMGRITEM;

The Problem:  I'm not sure what to make of the 'LPSYNCMGRITEM rgelt'
parameter in the method declaration.  It's a top-level pointer to an
array, but it's an [out] parameter.  So if I declare it with the C#
'out' keyword, I believe I'll end up with one too many levels of
indirection:

    int Next(
        int celt,
        out SyncMgrItem[] rgelt, // pointer-to-a-pointer?
        out int pceltFetched);

Will UnmanagedType.ByValArray rectify this?

    int Next(
        int celt,
        [MarshalAs(UnmanagedType.ByValArray)] out SyncMgrItem[] rgelt,
        out int pceltFetched);

Or, should I model it as a top-level pointer to an array, and specify
the direction with the [Out] attribute?

    int Next(
        int celt,
        [Out] SyncMgrItem[] rgelt,
        out int pceltFetched);

And in either case, how should I specify the size -- SizeParamIndex?
Which param?

Thanks in advance, interop gurus...
-Shawn
http://msdn.com/tabletpc
http://windojitsu.com

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to