Adding C++ DLL's to a C# project

KdgDev picture KdgDev · May 22, 2010 · Viewed 33.6k times · Source

I'm trying to use the lame_enc.dll file from LAME in a C# project, but adding the thing seems impossible.

I keep getting an error that says that a reference could not be added and to please check if the is accessible, a valid assembly or COM component.

I have no C++ experience, though I would like to use the functionality. Right now I'm using Process from the .NET framework to call lame.exe and do stuff, but I'd like to know if there's another way.

Answer

bitbonk picture bitbonk · May 22, 2010

You can only add managed assemblies as a reference to a managed project. What I normally do in this situation is to add it as ressource instead with "copy local" settings. That way the DLL is tied to and deployed with your project. I then use DllImport to manually get the APIs I need from that DLL.