I have an unmanaged C++ DLL which merely exports a single class (not COM...it's just a simple C++ class) as its interface. I want to use this class in C# but am told that it cannot merely be imported into C#.
What is the right way to use this class in my C# application?
DllImport is your best bet. There is a bit of data type massaging, especially if you are passing structs, but you can do almost anything with it.
Simple way assuming class Foo:
Then you make your c# code depend on the FooWrapper project/dll and ensure that the unmanaged dll is properly deployed with it, how that is done depends on the unmanaged dll but in the same directory is normally sufficient.
If the functions do not rely on instances of the class then even simpler is P/Invoke
You need an proxy (GoF pattern) intermediary to bridge the managed/unmanaged boundary.
Two options:
The former will be more direct, and latter has two steps pure C++ -> COM -> .NET.
This answer might be overkill for a single class library, but SWIG is a good solution for "wrapping" C/C++ classes for use from other languages. It works well with C#.
See http://www.swig.org/.
Sometimes, it is easier to provide your own C interface. SWIG is non-trivial to setup. I have use managed C++ and C++/CLI and they are fine. The easiest was just doing a C wrapper (and can be used by about any other language since most have a way to call a C function).