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]
# 1
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

ShawnFarkas-MS at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 2
hi,
thx for the reply :) it kind gave a basic idea of how to call this dll n libs. I will be pleased if you can give a link to site or something where i can find examples. or can u give a more detail explainations with examples.
savadi at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 3

For standard P/Invoke, look at MSDN documentation for the DllImportAttribute (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp). There also seems to be a series of MSDN Magazine articles on the topic:

http://msdn.microsoft.com/msdnmag/issues/03/07/NET/
http://msdn.microsoft.com/msdnmag/issues/04/10/net/default.aspx

As for writting a C++ bridge, I would start by checking out the Visual C++ forums (http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=96)

Hope that helps,
-Shawn

ShawnFarkas-MS at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 4
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.

Yiru at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...
# 5
Did some experiments with vorbis a year ago. Used VC++ to wrap static vorbislibs. Not that difficult to do. If your interested i could ftp you my sample code.
Razter at 2007-9-9 > top of Msdn Tech,.NET Development,Common Language Runtime...

.NET Development

Site Classified