1

I'm receiving an H264 stream over UDP. I'd like to decode the stream so I can send frames to OpenCV or whatever. I came across Cisco's open sourced H264 decoder here: https://github.com/cisco/openh264 With a little effort I got the decoder solution to build in Visual Studio 2019 and tested it from the command line with a file I created from the raw UDP datagrams. It works.

Now I want to figure out how to use the decoder DLL (welsdec.dll) in a C# project. The last time I did anything serious with C++ in Windows was back in the DirectShow and Delphi 5 days, so I'm completely lost.

Nothing in the H264 project is explicitly exported with __declspec(dllexport). Is that normal? Adding the DLL as a project reference to the C# project doesn't work ("the reference is invalid or unsupported").

I'm guessing the DLL is unmanaged. Can I consume that directly in C#? Am I going to have to rewrite the DLL as, or maybe or wrap it, in a C++ CX library to get this working?

Mark Lauter
  • 810
  • 9
  • 22

1 Answers1

3

You can consume an unmanaged DLL in C# explicitly using PInvoke.

You can also write an intermediary DLL in C++/CLI to ease the invocations between your managed C# application and the native DLL. This is the approach taken by secile/OpenH264Lib.NET per stuartd's comment.

It looks like the H264 project uses module definition files (.def) in lieu of decorating exports with declspec. You should still be able to access these publicly exported functions using the above methods.

  • 1
    Thank you for pointing me at the module definition files. That confirms what I found using dependency walker: http://www.dependencywalker.com/ So it should be as simple as getting the signature correct in a DllImport attribute. – Mark Lauter May 21 '19 at 02:53