views:

221

answers:

6

I trying to use a ".h" file from Windows SDK in a .NET language (maybe C#), but without success. This header exposes some Windows Media player functionality through COM. If I use Win32 C++, I can use it with no problems, so I thought that I could use Managed C++ as a "Bridge" to expose it to C#.

The header file is the subscriptionservices.h that comes with Windows Media Player SDK 11 (part of Windows SDK 6).

Is that possible? How could I use that header file in a .NET Application?

Thanks, Eduardo Cobuci

A: 

Try PInvoke. I don't think you can use the actual header, but you can reference functions in external unmanaged DLLs.

Chris Doggett
A: 

Yes - it is possible. P/Invoke is your friend. Use this link to translate the headers.

Platform Invoke Data Types

weismat
+1  A: 

You can use PInvoke to Interop with Win32. If you are trying to use a COM object you should be able to add a reference to the project. Have you looked at this article?

More practically you need to understand the kind of work that you are doing. If you are going to be doing lots of pointer arithmetic then I would recommend managed c++. If not C#. Good luck.

Steve
Was about to write the COM thing, so +1 for you instead. The header file is definitely COM.
OregonGhost
Yeah...COM interop is extremely useful since many microsoft API's are exposed as COM objects.
Steve
I wish OpenGL ES was COM - then it wouldn't be such a nightmare to use it from .NET ;) Well.
OregonGhost
+1  A: 

If there is a particular snippet of code or types that you are looking to use from the header file, you can paste them into the PInvoke Interop Assistant and get the C# code generated for you.

http://www.codeplex.com/clrinterop/Release/ProjectReleases.aspx?ReleaseId=14120

JaredPar
A: 

This might give you a head start on the C++ path, if you go that way.

http://code.msdn.microsoft.com/wmpinterop

Note that the WMP interface has some tricky interfaces to P/Invoke into. For me, it's easier just to write a C++ wrapper.

codekaizen
A: 

If the API is simply you can use PInvoke, if it's complicated I would suggest using C++/CLI. This allows you to create a 'bridge' between the managed and the unmanaged world.

compie