Main Menu

How do I write a wrapper?

Started by Draco9898, October 26, 2006, 06:03:15 AM

Previous topic - Next topic

Draco9898

I'd like to write wrappers for various things such as PhysX, shader Dlls, etc.
Any info is appreciated, thanks
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

kevin

#1
 

PlayBASIC Code: [Select]
LinkDLL  MyDll
MyPbFunction(params) alais "NameOfFunctionInDll" as returntype

etc
EndLInkDll





stef

#2
Hi!

That's interesting! But is it possible to explain it a little more?

If  I run the 'coldsteel terrain example' I got an error message (because I haven't coldsteel/coldsteel.dll)

But you can see now the file 'coldsteel3D.PBA' (out of SLIB-folder).I think this is the (coldsteel)wrapper.

How can I load or save a PBA file?

stef

#3
QuoteHow can I load or save a PBA file?

Hm
Of course with 'Manage Project..' in 'Project' menu.
Sorry!  ::)

stef

#4
Hi

The problem with extern programs/dll's is that you must be engaged in this programs and understand them.

I think Coldsteel contains more than 300 functions.
It's a lot of work to write a wrapper (like Kevins coldsteel3d.pba) for these functions.

But it is much more work for developers to understand and use these functions in own programs.

kevin

#5
  PB provides two approaches for wrapping external DLL's.   Those are DLL blinding and the DLL command set.   Both effectively achieve the same result.   There's also support library for ActiveX and .Net Dll's but that's empty's field really.

  DLL blinding is a way of importing an external function into your program as a PB function.  For this we use the LinkDLL/EndLinkDLL declaration blocks (see help).  This occurs at compile time  Once your functions are suitable declared, these linked functions can be used through your programs just like any user defined function.

 The Dll commands provide a hands approach for calling functions.   Which occur at runtime.
  In order to wrap a  DLL(s) successfully the programmer needs some idea of their doing. (plus the dll comes with an SDK)   In particular importance is the data types that each dll functions requires as input and results.  Some data types will require some 'piping' in and out.  Be it in PB or some other language like C/Delphi etc

 If the dll doesn't come with an SDK but has other wrappers, then you can just convert the wrapping code.  Which is what the Blitz to LinkDll function does here (login required)   Which is certainly a lot easier than doing it by hand.

 In the end, a wrapper is really no different than a regular function set.