You will have to be careful with the ppPropVariant pointer pointer.

The documentation is a little contradictory. First the docs claim that
ppPropVariant is a pointer to an output variable that receives a pointer to
the PROPVARIANT. But then the docs go on to say in Notes to Callers:
Allocate the PROPVARIANT structure with CoTaskMemAlloc.

Well, does the caller allocate the memory or the interface implementer? My
hunch would be that the IFilter implementer is sending you a pointer and
that you will not need to free it.

I would recommend using an IntPtr rather than UnmanagedType.Struct. Here is
some untested code:

[PreserveSig]
Int32 GetValue(out IntPtr ppPropValue);

And then call it like this:

PROPVALUE propval;
IntPtr ppPropValue = new IntPtr(0);
Int32 ret = pIFilter.GetValue(out ppPropValue);
if(ret != some_error_value && ppPropValue != IntPtr.Zero)
{
        propval = (PROPVALUE)
                Marshal.PtrToStructure(ppPropValue,
                typeof(PROPVALUE));
        /* Do something with it */
}

You might also be able to make it work by changing your UnmanagedType.Struct
to an UnmanagedType.LPStruct but I'm not entirely sure about that.

--
Peter



> Erick Thompson spake:
>
>
> Mattias,
>
> I think that decimal cyVal member was the problem. After I removed it, the
> type was able to load. However, I'm getting a weird exception when I call
> GetValue.
>
> An unhandled exception of type 'System.OutOfMemoryException' occurred in
> felix.dll
> Additional information: Not enough storage is available to complete this
> operation.
>
> The signature for GetValue is
>
> [PreserveSig]
>
> int GetValue(
>
>     [MarshalAs(UnmanagedType.Struct)]
>
>     out PROPVARIANT ppPropValue
>
> );
>
>
> I'm calling it with
>
> PROPVARIANT var;
>
> filter.GetValue(out var);
>
>
>
> The exception occurs here. I have no idea what could be causing this
> exception. Any ideas?
>
> Thanks,
> Erick

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to