Wrappers, what are they and how do they work?

For everything that's not in any way related to PureBasic. General chat etc...
Nituvious
Addict
Addict
Posts: 1030
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Wrappers, what are they and how do they work?

Post 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)?
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

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

Post 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.
BERESHEIT
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

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

Post by blueznl »

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

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

Post 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.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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
"Have you tried turning it off and on again ?"
Nituvious
Addict
Addict
Posts: 1030
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

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

Post by Nituvious »

Thanks guys!
I was half expecting these snide remarks :P . No mention to MC Hammer though! :lol:
▓▓▓▓▓▒▒▒▒▒░░░░░
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

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

Post 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 :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply