We help IT Professionals succeed at work.

How to include the external libtorrent DLL in vlc (crosscompiled on ubuntu for win32)

Exxor
Exxor asked
on
What I'm trying to do is make use of the libtorrent library in vlc. I'm confused about the general way of doing this.

What I figured out is:
-How to build a DLL from the libtorrent sourcecode
-How to crosscompile vlc on ubuntu for win32

What I'm confused about is:
-How to link against a DLL in vlc
-If there's anything else I need to do except linking against the DLL to get it to work?
-What kind of include statements to use in the vlc sourcecode to reference the libtorrent functions

What I would really like is some tutorial/overview/explenation of what the general idea is on how to accomplish something like this, because I feel like walking with a blindfold on.
Comment
Watch Question

Senior Software Engineer (Avast)
Commented:
Let's see if I can get you started on this neglected question...

-How to link against a DLL in vlc

When you build a DLL the compiler also generates a static library that you can link against. All this contains is stub code that will load the DLL at runtime and allow you to call functions against it. You can also load the DLL yourself at runtime using the LoadLibrary function but that requires a lot more work since you'll also have to write you own code to import the functions from the DLL.

The following link is to a tutorial that shows you how to create and use a DLL
"Walkthrough: Creating and Using a Dynamic Link Library"
http://msdn.microsoft.com/en-us/library/ms235636(v=VS.80).aspx

-If there's anything else I need to do except linking against the DLL to get it to work?

See what I wrote above

-What kind of include statements to use in the vlc sourcecode to reference the libtorrent functions

When you build code that is destined to be a DLL you have to include a special declaration for the functions that will be exported. Likewise, when you use a DLL you need to include a special declaration for functions that will be imported. This can be simplified by using the same header file for both and using a precompile directive to control whether the functions are exported or imported.

"dllexport, dllimport"
http://msdn.microsoft.com/en-us/library/3y1sfaz2(v=VS.80).aspx

This link explains in more detail the different ways to link to a DLL
"Linking an Executable to a DLL"
http://msdn.microsoft.com/en-us/library/9yd93633(VS.90).aspx

See below for an example

Finally, a link to various info on DLLs that you may find useful
http://msdn.microsoft.com/en-us/library/1ez7dh12.aspx

I hope this all helps.

#define DllImport   __declspec( dllimport )
#define DllExport   __declspec( dllexport )

#ifdef STATIC_LINK
   #define DLL_FUNC__  
#else
   #ifdef DLL_EXPORT
      #define DLL_FUNC__ DllExport
   #else
      #define DLL_FUNC__ DllImport   
   #endif
#endif

// will either have no linkage if building as a static library
// exported if DLL_EXPORT is defined else imported. In your main
// project you should define DLL_EXPORT as a project level preprocessor
// macro to export the function foo(). In the consuming project you just
// use this header and it will import the function foo()
DLL_FUNC__ void func(); 

Open in new window