> I've added a library to the project I'm currently working on which
> contains
[quoted text clipped - 13 lines]
> Value of type 'WMEncoderLib.IWMEncProfile' cannot be converted to
> 'System.IntPtr'.
did you try ASFConfig.ConfigureFilterUsingProfile(new IntPtr(EncProfile))?
Also, perhaps you just need to change the DllImport statement for
ConfigureFilterUsingProfile to have a IWMEncProfile parameter instead of
IntPtr.
> How can I get a pointer to my EncProfile object? I'd be much obliged to
> anyone who can point me in the right direction (lame joke, but what the
> heck).
Mark Raishbrook - 07 Nov 2006 22:32 GMT
Thanks for the reply, Ben.
> did you try ASFConfig.ConfigureFilterUsingProfile(new IntPtr(EncProfile))?
No, I haven't tried that yet. Will do. Thanks for the tip.
> Also, perhaps you just need to change the DllImport statement for
> ConfigureFilterUsingProfile to have a IWMEncProfile parameter instead of
> IntPtr.
It's not actually a DLL import. It's a COM assembly added to the project
which exposes this function, so I can't change it I'm afraid.
Mark Raishbrook - 07 Nov 2006 22:39 GMT
> did you try ASFConfig.ConfigureFilterUsingProfile(new IntPtr(EncProfile))?
"Overload resolution failed... Value of type 'WMEncoderLib.IWMEncProfile'
cannot be converted to 'Long/Integer".
Where's Hard Core Visual Basic when you need it? :-)
Mark,
>How can I get a pointer to my EncProfile object?
Use Marshal.GetComInterfaceForObject (and Marshal.Release when you're
done).
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mark Raishbrook - 08 Nov 2006 16:01 GMT
> >How can I get a pointer to my EncProfile object?
>
> Use Marshal.GetComInterfaceForObject (and Marshal.Release when you're
> done).
Thanks for the tip, Mattias.
I'm now getting an "Attempted to read or write protected memory" error when
using the pointer returned by Marshal.GetComInterfaceForObject. Silly
Question of the Week: do I have to store it in a separate variable and call
Marshal.Release immediately before using it?
Mattias Sjögren - 08 Nov 2006 19:30 GMT
Mark,
>Question of the Week: do I have to store it in a separate variable and call
>Marshal.Release immediately before using it?
Yes you have to store it, but you shouldn't call Release until after
you're done using it (i.e. after the call to
ConfigureFilterUsingProfile).
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mark Raishbrook - 08 Nov 2006 22:39 GMT
> Yes you have to store it, but you shouldn't call Release until after
> you're done using it (i.e. after the call to
> ConfigureFilterUsingProfile).
Still no luck, I'm afraid, and I've tried several ways. Does the following
code snippet shout "This wrong!" at you?
'* Add the ASF writer. Must be configured before connecting upstream
ASFWriter = DirectCast(New WMAsfWriter(), IBaseFilter)
hr = GraphBuilder.AddFilter(ASFWriter, "ASF Writer")
'* Load the custom WME profile
EncProfile = New WMEncProfile2
EncProfile.LoadFromFile("C:\Program Files\Windows Media
Components\Encoder\Profiles\UserProfile.prx")
'* Get a pointer to it
Dim ppProfile As IntPtr = Marshal.GetComInterfaceForObject(EncProfile,
GetType(WMEncProfile2))
'* Configure writer using custom profile
ASFConfig = DirectCast(ASFWriter, IConfigAsfWriter)
ASFConfig.ConfigureFilterUsingProfile(ppProfile)
'* Release interface pointer ref
Marshal.Release(ppProfile)
The "Attempted to read or write protected memory" error occurs at the
ConfigureFilterUsingProfile call (although the HRESULT is 0).
Any ideas? I've wasted enough of your time as it is, so please don't worry
if nothing appears to be wrong!