Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / November 2006

Tip: Looking for answers? Try searching our database.

Pointer to interface?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Raishbrook - 07 Nov 2006 20:22 GMT
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).
Ben Voigt - 07 Nov 2006 22:20 GMT
> 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? :-)
Mattias Sjögren - 08 Nov 2006 05:54 GMT
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!

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.