Page 1 of 1

Wrappers, what are they and how do they work?

Posted: Sun Nov 28, 2010 8:41 pm
by Nituvious
What exactly is a wrapper? How do programmers make them?
For example, if I have a DLL that was developed in C++ how would a wrapper be made for it to work in PureBasic(if this is even really needed)?

Re: Wrappers, what are they and how do they work?

Posted: Sun Nov 28, 2010 11:15 pm
by netmaestro
A decent-sized dll will have constants, structures and exported functions in it, maybe macros and resources too such as graphics. To use the functions you'll need to know their prototypes (number and type of parameters in what order and return type), as well as what the constants and structures are and the location, size and type of any resources. A wrapper defines all these things within your program with a list and/or enumerations of the constants, declarations for the structures, any macros, prototypes for the functions and locations/sizes for the resources. With the wrapper included to your source, all you have to do is open the dll via OpenLibrary or Import, and from there you can just use it.

Re: Wrappers, what are they and how do they work?

Posted: Mon Nov 29, 2010 8:59 am
by blueznl

Re: Wrappers, what are they and how do they work?

Posted: Mon Nov 29, 2010 3:27 pm
by Trond
http://www.chocablog.com/wp-content/upl ... 07/mm1.jpg

Yo, scratch-scratch, I'm em-n-em, the candy (w)rapper!

Let's pretend PB didn't support doubles. If you wanted to use a dll with functions that take doubles as parameters you would need a wrapper. This wrapper could be another dll, which exports functions similar to the ones found in the first dll, except with float parameters instead of doubles. Then the wrapper would convert from float to double and call the real dll.

Re: Wrappers, what are they and how do they work?

Posted: Mon Nov 29, 2010 3:39 pm
by luis
Nituvious wrote:What exactly is a wrapper? How do programmers make them?
http://en.wikipedia.org/wiki/Wrapper_library
http://en.wikipedia.org/wiki/Wrapper_function

Re: Wrappers, what are they and how do they work?

Posted: Mon Nov 29, 2010 10:11 pm
by Nituvious
Thanks guys!
I was half expecting these snide remarks :P . No mention to MC Hammer though! :lol:

Re: Wrappers, what are they and how do they work?

Posted: Tue Nov 30, 2010 12:35 am
by blueznl
Apologies, but I was struggling with a big inter-department budget-related fight, and I needed some light entertainment... (un)fortunately 8) you came along :-)