|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Pointer to interface?I've added a library to the project I'm currently working on which contains
the following function: ConfigureFilterUsingProfile(ByVal pProfile As System.IntPtr) As Integer pProfile is a pointer to the Windows Media Encoder interface IWMEncProfile. If I create a profile -- Dim EncProfile As IWMEncProfile -- and try and pass this to the function -- ASFConfig.ConfigureFilterUsingProfile(EncProfile) -- I (obviously) get the following error message: Value of type 'WMEncoderLib.IWMEncProfile' cannot be converted to 'System.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).
Show quote
"Mark Raishbrook" <MarkRaishbr***@discussions.microsoft.com> wrote in did you try ASFConfig.ConfigureFilterUsingProfile(new IntPtr(EncProfile))?message news:17A1E25F-83E1-443D-8F04-3CD471A97B9A@microsoft.com... > I've added a library to the project I'm currently working on which > contains > the following function: > > ConfigureFilterUsingProfile(ByVal pProfile As System.IntPtr) As Integer > > pProfile is a pointer to the Windows Media Encoder interface > IWMEncProfile. > > If I create a profile -- Dim EncProfile As IWMEncProfile -- and try and > pass > this to the function -- > ASFConfig.ConfigureFilterUsingProfile(EncProfile) -- > I (obviously) get the following error message: > > Value of type 'WMEncoderLib.IWMEncProfile' cannot be converted to > 'System.IntPtr'. Also, perhaps you just need to change the DllImport statement for ConfigureFilterUsingProfile to have a IWMEncProfile parameter instead of IntPtr. Show quote > > 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). 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 It's not actually a DLL import. It's a COM assembly added to the project > ConfigureFilterUsingProfile to have a IWMEncProfile parameter instead of > IntPtr. which exposes this function, so I can't change it I'm afraid. > 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'redone). Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. "Mattias Sjögren" wrote: Thanks for the tip, Mattias.> >How can I get a pointer to my EncProfile object? > > Use Marshal.GetComInterfaceForObject (and Marshal.Release when you're > done). 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? Mark,
>Question of the Week: do I have to store it in a separate variable and call Yes you have to store it, but you shouldn't call Release until after>Marshal.Release immediately before using it? you're done using it (i.e. after the call to ConfigureFilterUsingProfile). Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. > Yes you have to store it, but you shouldn't call Release until after Still no luck, I'm afraid, and I've tried several ways. Does the following > you're done using it (i.e. after the call to > ConfigureFilterUsingProfile). 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! |
|||||||||||||||||||||||