Tutorial :Using a C++ header with .NET language


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


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.


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.



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


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

Platform Invoke Data Types


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


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


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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »