Calling unmanaged c++ dll's and lib's into c# using visual studio 2005 beta
Hi, i would like to find out what are the ways to call unmanaged c++ dll's and lib's into c# using visual studio 2005 beta. I have tried many ways like using p-invoke and adding through reference but none of these methods seemed to do it for me. Are there any easier ways to perform this operation using Visual Studio 2005 Beta? I would like to create an application that uses certain dll's and lib's from the ogg vorbis library and implement them into my windows application whereby the GUI would be done using C#. The url for the ogg vorbis codes are as follows. www.vorbis.com. I would really appreciate your kind feedback. Thank you.
[642 byte] By [
savadi] at [2008-2-14]
For standard C-style function exports of a .dll, your best bet is to P/Invoke out to it. (This does not require adding a reference to the dll in Visual Studio, although Windows will need to be able to find your .dll when running the application, so it will have to either be copied into your output directory, or placed somewhere on the path). If you're trying to call C++ objects, probably the easiest route would be to create a Managed C++ project which acts as a bridge between the managed world and the unmanaged objects. Since MC++ code can expose a managed object model, while still calling unmanaged code you can wrap the Vorbis OM in your own bridge layer.
You cannot directly use a .lib, although you could build a dll that just wrapped around the .lib and use one of the techniques above. The MC++ technique will also work out well here.
-Shawn
There are two ways to use unmanaged C++ dll's. If your C++ dll expose static entry points, you can use PInvoke to invoke on the function. If you C++ dll is a Com object, you can use interop to invoke on the function.
You should probably ask how to do interop through Visual Studio in the VS forum. I think they should have more knowledge about that.
Thanks.